It is so frustrating how unecessarily complicated AS is. All I am trying to do is when a dialog box comes up and the user hits the “quit” button that the script -quits. Unfortunately it keeps running through the rest. I tried using “quit” or “exit” or “stop” but nothing that common sense predicts, works.
Yet another question:
I am using:
tell application “Finder”
move every file of thisFolder to topFolder
To move files between folders. How can I tell the script only to move files
that have the ending .jpg or .crw and to delete the remaining folders after
move is complete?
set dd to (display dialog "Hi" buttons {"Hi", "Quit"} default button 2)
if button returned of dd is "Quit" then return
display dialog "The script is still running"
This might work with moving the designated files.
tell application "Finder"
try
move (files of thisFolder whose name extension is "jpg" or name extension is "crw") to topFolder
on error e
display dialog e buttons {"OK"} default button 1
return -- quit
end try
delete folders of thisFolder
end tell
Note: This script will move only the files at the root level of thisFolder. It will not move files from sub-folders of thisFolder (it can be done but this script won’t do it).
Further to Rob’s reply, ‘display dialog’ automatically generates a ‘User canceled’ error if the user clicks on a button labelled “Cancel” (or its equivalent on non-English systems). This stops a script dead in its tracks unless you make arrangements to trap the error. If you want to quit a script with some other button label, you can generate the error yourself. Its number is -128.
set dd to (display dialog "Hi" buttons {"Hi", "Quit"} default button 2)
if button returned of dd is "Quit" then error number -128
display dialog "The script is still running"