Sunday, July 5, 2020

#1 2011-03-05 01:18:57 pm

e3den
Member
Registered: 2011-03-05
Posts: 40

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

Offline

 

#2 2011-03-05 01:26:53 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11688
Website

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

Hi,

there are several methods, this is one

Applescript:


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


regards

Stefan

Offline

 

#3 2011-03-09 05:22:35 am

e3den
Member
Registered: 2011-03-05
Posts: 40

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

Hi!

I get a "sintaxis error" sad

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

Offline

 

#4 2011-03-09 05:51:43 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2809
Website

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

Another way and not using using the Finder

Applescript:

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

Offline

 

#5 2011-03-09 07:15:52 am

e3den
Member
Registered: 2011-03-05
Posts: 40

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

if i do this
 

Applescript:


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

Applescript:


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!

Offline

 

#6 2011-03-09 09:24:41 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2809
Website

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

If input is an alias your should change

Applescript:

set ThePath to input

to

Applescript:

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.

Last edited by DJ Bazzie Wazzie (2011-03-09 09:27:16 am)

Offline

 

#7 2011-03-09 09:37:36 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11688
Website

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

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

Applescript:


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

Last edited by StefanK (2011-03-09 09:38:55 am)


regards

Stefan

Offline

 

#8 2011-03-09 10:38:54 am

e3den
Member
Registered: 2011-03-05
Posts: 40

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

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)

sadhmm

Last edited by e3den (2011-03-09 11:07:21 am)

Offline

 

#9 2011-03-09 10:43:16 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11688
Website

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

what Automator action comes before the Run AppleScript action?


regards

Stefan

Offline

 

#10 2011-03-09 11:08:26 am

e3den
Member
Registered: 2011-03-05
Posts: 40

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

Get value of variable

Offline

 

#11 2011-03-09 11:14:50 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11688
Website

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

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


regards

Stefan

Offline

 

#12 2011-03-09 11:29:56 am

e3den
Member
Registered: 2011-03-05
Posts: 40

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

/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

Last edited by e3den (2011-03-09 11:33:34 am)

Offline

 

#13 2011-03-09 11:44:37 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11688
Website

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

the correct coercion result of

Applescript:


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

must be
[code]folder01[/code]
if the (shared) volume is mounted. If the volume is not mounted, you should get
[code]"[name of startup volume]:Volumes:folder01"[/code]

Last edited by StefanK (2011-03-09 11:45:01 am)


regards

Stefan

Offline

 

#14 2011-03-09 12:00:38 pm

e3den
Member
Registered: 2011-03-05
Posts: 40

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

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

Last edited by e3den (2011-03-09 12:15:17 pm)

Offline

 

#15 2011-03-09 12:19:10 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11688
Website

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

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

Applescript:


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

Last edited by StefanK (2011-03-09 12:20:10 pm)


regards

Stefan

Offline

 

#16 2011-03-09 12:26:11 pm

e3den
Member
Registered: 2011-03-05
Posts: 40

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

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

Offline

 

#17 2020-04-05 11:16:18 am

TheIaMonLyOneHeRe
Member
Registered: 2018-09-16
Posts: 41

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

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

i try:

Applescript:

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

to no avail here.

Last edited by TheIaMonLyOneHeRe (2020-04-05 11:17:10 am)

Offline

 

#18 2020-04-05 12:48:07 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4534

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

You may use something like :

Applescript:

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

Online

 

#19 2020-04-05 02:25:26 pm

TheIaMonLyOneHeRe
Member
Registered: 2018-09-16
Posts: 41

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

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.

Offline

 

#20 2020-04-06 05:59:24 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

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

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):

Applescript:


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

Last edited by KniazidisR (2020-04-06 07:06:01 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)