We have a lot of applescript’s doing a lot of different things throughout the day. For now, we have them running about five minutes apart to keep them from overlapping and screwing up each other.
Is there some solution that would allow us to basically run one, then another after that, but, until the first one is done, the second, third etc. just go into a queue and wait for the first to finish…?
Hi,
I’m sure that there’s a lot of different ways of doing this but give this example a try:
tell application "Finder" to display dialog "Hello"
Save the above script to your desktop and call it script1.scpt then
beep 10
Save the above script to your desktop and call it script2.scpt then
set script1 to (path to the desktop as string) & "script1.scpt" as alias
set script2 to (path to the desktop as string) & "script2.scpt" as alias
run script script1
run script script2
try running this code from your script editor.
The point I’m trying to make is that if you have all you scripts saved you could run them from one script consecutively. You could even include “idle” handlers in the script and save it as a “Stay Open” application.
I’m sure that there will be a lot more suggestions but I hope this helps?
Nik
at the beginning of my cron-run applescripts i have them look for a specific file sitting at root. if the file doesn’t exist, I have the applescript create that dummy folder at root (you can put it wherever). at the end of running, i have it delete the file.
tell application "Finder"
if (exists folder "StudioAutomation:flag") = false then
my runprog()
end if
end tell
to runprog()
do shell script "mkdir /flag"
try
do whatever etc etc...
do shell script "rmdir /flag"
that seems to work. you might put in a delay if you want to be sure there is no crash.
I have this code in a couple of my apps. It is the same external switch concept that Ralph posted, but I use the fact that a text file can only be open for access by one app at a time. There is code that goes at the start of whenever the app should “take control” of the computer, and another short block of code to go at the end when the app is ready to give up control.
I guess I should mention that I test this a couple times but have yet to put it in use on a permanent basis, so hopefully there are no issues that come up.
--Use APP_SWITCHER code to determine if other AppleScripts are currently running
set AppSwitchTextFile to ((path to application support from user domain as text) & "Chase_App_Switcher.txt")
try
set the openFile to open for access file AppSwitchTextFile with write permission
set idleOrActive to "Idle"
on error
set idleOrActive to "Active"
end try
repeat while idleOrActive is not "Idle"
try
set the openFile to open for access file AppSwitchTextFile with write permission
set idleOrActive to "Idle"
on error
set idleOrActive to "Active"
--tell window "mainWindow" to set contents of text field "statusText" to ("Waiting for other AppleScripts to complete...") --This was from an XCode project
end try
delay 5
end repeat
--END of APP_SWITCHER section. One additional line at end of if then loop needed to close out this script
--APP_SWITCHER last part
try
close access file AppSwitchTextFile
on error --If access to the text file can't be closed, try to delete the file so it will work next time.
set theShell to ("rm -f \"" & (POSIX path of AppSwitchTextFile) & "\"")
try
do shell script theShell
end try
end try
--END APP_SWITCHER
Model: iMac Intel 10.5.5
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)