Repeat while not exists a file with mov extension in a specific folder

Hi!

I want create a loop to pause my applescript until detect that a file with extension mov appear in a specific folder …

something like:

tell application “Finder”
activate
repeat while not (exists file with “mov” filetype (path))
delay 1
end repeat
end tell


i dont know how write this well.
Thank for your help

Hi,

there are several methods, this is one


set theFolder to path to desktop
tell application "Finder"
	repeat until (count (files of theFolder whose name extension is "mov")) > 0
		delay 1
	end repeat
end tell

Hi!

I get a “sintaxis error” :frowning:

I copy and paste the code here:

on run {input, parameters}
set ruta to (input as text)
– display dialog (ruta)
tell application “Finder”
activate
repeat until (count (files of input whose name extension is “mov”)) > 0
delay 2
end repeat
end tell
display dialog “¿Parece que ya has generado la movie, se va a entregar la version en avi” with icon caution buttons {“Continuar”}
return input
end run

input variable is a path like: “/Volumes/folder/folder 01 (test)”
this is a applescript in automator

thanks

Another way and not using using the Finder

on run{input, parameters}
repeat until fileExists(posix path of (input as string))
	delay 0.2
end repeat
display dialog "¿Parece que ya has generado la movie, se va a entregar la version en avi" with icon caution buttons {"Continuar"}
    return input
end run 

on fileExists(posixFile)
	return not ((do shell script "test -e " & quoted form of posixFile & " ;echo $?") as integer) as boolean
end fileExists

if i do this


  set ThePath to "/Volumes/folder"
  return {POSIX file ThePath, (POSIX file ThePath) as string}
	display dialog (ThePath)

i get path converted well with :

but if i try to get a input value like this


on run {input, parameters}
  set ThePath to input
  return {POSIX file ThePath, (POSIX file ThePath) as string}
	display dialog (ThePath)

i get a error… i dont know what?? missing quotes " "… i dont calling value in input well, input only have a value like /Volumes/folder in it, what are im doing wrong?

thanks!

If input is an alias your should change

set ThePath to input

to

set ThePath to input as string

The reason I did the conversion when calling the handler is so I don’t need another variable (overhead) and also the variable input won’t get affected.

in an Automator action input is a list of objects in most cases

if the list contains only one item, coercing to text flattens the list.
If the list contains more than one item, the script will fail.

Try this, it takes the first item of the list and coerces to HFS path


on run {input, parameters}
	set inputHFSPath to POSIX file (item 1 of input) as text
	tell application "Finder"
		repeat until (count (files of folder inputHFSPath whose name extension is "mov")) > 0
			delay 1
		end repeat
	end tell
	return input
end run


stored (item 1 of input) is “/Volumes/folder01” and dont work.
if i change manually the variable to “Volumes/folder01” without first slash then the POSIX conversion is OK, is automator that store this value in input, how i can do to run ok?

set inputHFSPath to POSIX file “/Volumes/folder01” as text ----> return :folder01
set inputHFSPath to POSIX file “Volumes/folder01” as text ----> return :Volumes:folder01
set inputHFSpath to POSIX file (item 1 of input) as text ----> return ERROR if (item 1 of input = /Volumes/folder01)
set inputHFSpath to POSIX file (item 1 of input) as text ----> return :Volumes:folder01 if (item 1 of input = Volumes/folder01)

:(:confused:

what Automator action comes before the Run AppleScript action?

Get value of variable

I guess there’s something wrong with the passed path

/Volumes/folder01 normally points to a external volume (disk) named folder01.
If there is no disk folder01 the POSIX file coercion fails

/Volumes/folder01 is an example of a mounted network volume, the actual path is longer, but im sure that exist. If i remove the first slash the conversion is ok… i can send you the automator workflow if you want.

this is my error and try

set inputHFSPath to POSIX file “/Volumes/folder01” as text ----> return :folder01
set inputHFSPath to POSIX file “Volumes/folder01” as text ----> return :Volumes:folder01
set inputHFSpath to POSIX file (item 1 of input) as text ----> return ERROR if (item 1 of input = /Volumes/folder01)
set inputHFSpath to POSIX file (item 1 of input) as text ----> return :Volumes:folder01 if (item 1 of input = Volumes/folder01)

thanks

the correct coercion result of


set inputHFSPath to POSIX file "/Volumes/folder01" as text

must be

folder01

if the (shared) volume is mounted. If the volume is not mounted, you should get

"[name of startup volume]:Volumes:folder01"

the shared volume is mounted and working.

Can you try this simple automator workflow?

1º New folder
2º set value of variable (this give you a new variable with /Volumes/thePath/newfolder) (problematicpath is the name of variable)
------- ignore input data
3º get value of variable (problematicpath)
4º run applescript
on run {input, parameters}
set inputHFSPath to POSIX file (item 1 of input) as text
return inputHFSPath

this workflow fail in 4º step, but if manually modify the content of variable “problematicpath” and remove the first slash, the result seems be ok “:Volumes:thePath:newfolder”

very annoying :S

i need that work automatically of course

sorry for the work, and a lot of thanks

OK, the problem is, the variable contains a list of aliases, not POSIX paths
The alias can be used directly


on run {input, parameters}
	set inputAlias to (item 1 of input)
	tell application "Finder"
		repeat until (count (files of inputAlias whose name extension is "mov")) > 0
			delay 1
		end repeat
	end tell
	return input
end run

thaaaaaanks, you are my God, works perfectly now!!

Is there any way to go through a variable and
while she returns a word to me do something?

i try:

repeat var until contains "Hello"
if var contains "Hello" then
...........
end repeat

to no avail here.

You may use something like :

repeat until var contains "Hello"
	-- Here, var contains "Hello"
	-- do your duty
end repeat

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 5 avril 2020 20:47:51

thanks @Yvan Koenig,
I tried, but ended up in an infinite loop.
ok, i’ll explain better, i’m running a shell command that informs me of the connected external devices, like pendrives.
if he verifies that he has an external device connected he takes his name and inserts it in a Label, but what happens is that if I have 2 external devices he inserts the same name for both.
I’m sorry if I wasn’t clear.

Here is how you can check concrete USB devices is connected or not, and if they are connected then add to labels list (simple and fast way, without getting detailed info for them):


set usbNames to {"someNot_HARD_DISK", "myRemovableUSB_1", "myRemovableUSB_2"}

set allDisks to paragraphs of (do shell script "cd /Volumes; ls")

set USB_labels to {}
repeat with i from 1 to count usbNames
	set usbName to item i of usbNames
	if allDisks contains usbName then set end of USB_labels to usbName
end repeat
return USB_labels