Thursday, January 19, 2017
  • Index
  •  » Core Language
  •  » How can I use a command, but not wait for it to be finished?

#1 2005-10-13 03:17:59 pm

julifos
Administrator
From: MalasaƱa, Madrid
Registered: 2002-11-20
Posts: 2014

How can I use a command, but not wait for it to be finished?

The statement "ignoring application responses" does exist. It will pass instructions to an application and won't wait for the answer, then the script will continue executing. This is useful if you must duplicate a folder (for example) but it will take a long time.  If you prefer to monitor the process, instead of waiting for the Finder to tell you "it is ready", try this:

Applescript:

set folderToDuplicate to alias "path:to:dir:"
set targetFolder to alias "path:to:dir2:"

set {originalName, originalSize} to {name, size} of (info for folderToDuplicate)

ignoring application responses
   tell application "Finder"
       duplicate folderToDuplicate to targetFolder
   end tell
end ignoring

delay 1 --> wait while duplicate process starts

repeat
   set currentSize to size of (info for alias ((targetFolder as text) & originalName))
   set currentPercent to round (currentSize * 100 / originalSize)
   if currentPercent is 100 then
       exit repeat
   else
       display dialog (currentPercent as text) & "% done..." with icon note giving up after 1
   end if
end repeat

display dialog "Done!" with icon note giving up after 3

This statement, though, will work only if you are targetting an application. For example:

Applescript:

ignoring application responses
   display dialog "foo"
end ignoring

This code will not finish while you don't dismiss manually the dialog. However:

Applescript:

tell application "Finder"
   ignoring application responses
       display dialog "foo"
   end ignoring
end tell

This code will pass the "display dialog" command to the Finder, and won't wait for the result of such dialog.


Filed under: Finder

Offline

 
  • Index
  •  » Core Language
  •  » How can I use a command, but not wait for it to be finished?

Board footer

Powered by FluxBB

[ Generated in 0.077 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)