If you run an AppleScript that does something and quits as a folder action, how can you tell if it is still running or just didn’t do anything? For example, while debugging, the script could get stuck in a loop or it could bail out without doing anything. How do you tell the difference? Or even kill it if you want?
To kill it, if its not running from S.E, but a folder action.
I kill System Events and the re Activate it.
tell application "system Events" to quit
delay 5
tell application "system Events" to activate
To debug add a debugging property :
property debugging : true
then just before and after where you want to check what the script is doing add a line like:
if debugging is true then say "setting next item"
I.e
repeat with i from 1 to number of items in mytest
if debugging is true then say "setting next item"
set this_item to item i of mytest
if debugging is true then say "doing something"
set this_thing to do_somthing
end repeat
if debugging is true then say "repeat finished"
I’ve been doing a similar debugging thing with a variable that I set at different levels to turn sets of debugging notices on and off. I’ve been using “display dialog” as the notice though and that gets a little annoying after awhile. Using “say” is a cool idea.
I’m assuming that there is no way, for example “ps” or Activity Monitor, that would show if that specific script is still running? I can think of a few scenarios where not getting one of the debug responses doesn’t mean that the script isn’t still running somewhere.
Thanks for the ideas. I’ll give them a shot.
T.
Hi trinkel,
You can also use the «logger» command to easily and conveniently log certain messages to the system log, which can be viewed with the Console application:
set msg to "This is a debugging message!"
do shell script "logger " & msg
Normally running scripts can be identified by their name using System Events. But I don’t know, if individual Folder Actions can be accessed…
set scriptname to "Yodeldido"
tell application "System Events"
set allprocnames to get name of every process
if scriptname is in allprocnames then
return true
else
return false
end if
end tell
Maybe this is of some help?
Thanks for the information about logging. I’ve got the script squared away now, but that’s something I’ve always wanted to figure out.
Thanks again to everybody who helped out here.
T.