 |
 |
Getting feet wet...
|
 |
|
 |
|
Forum Regular
Join Date: Nov 1999
Status:
Offline
|
|
I don't know much about AppleScript and haven't had the need to use it until now. I would like to know if it is possible to write an AppleScript that would quit all open programs at a specific time and then launch SETI@home. This seems like a fairly easy thing to do, but I am not sure if you can have control over the exact time of events (or how you would write the time control code). Any help would be appreciated.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status:
Offline
|
|
The script itself is pretty straightforward. the following script will loop through running applications (excluding the Finder) and tell them to quit:
Code:
tell application "Finder"
-- get running applications
-- use 'whose visible is true' to only get appications not background processes
set theApps to name of every application process whose visible is true
-- loop through the apps
repeat with anApp in theApps
-- 'try' handles basic error handling
try
-- excluding the Finder (the * is option-=)
if anApp * "Finder" then
-- and tell them to quit
tell application anApp
quit
end tell
end if
on error
end try
end repeat
end tell
However, there's no handling for saving documents. if an application asks if you want to save a document the script will not be able to quit it. The script won't fail due to the 'try/end try' handler. but the application won't quit.
You cold modify the script to walk through open documents in each application, saving them as you go, but that may be dependent on application support.
The second part of the requirement, launching SETI is harder. SETI itself isn't scriptable, so you can't launch it directly via AppleScript.
However, you could either:
- Set SETI to start automatically after a certain idle time
- Set SETI's Hot-Key launch and have the script simulate that command key (using AutoType, for example)
- Enable the 'hot corner' and have the script move the mouse to that corner when it's done
The final requirement, to run automatically, is easy to do using MacOS 9's Script Scheduler control panel. if you're not running OS 9 you can install iDo's Script Scheduler (a more fully-featured version of the app Apple ships with OS 9, or install cron to launch the script at preset times.
Hope this helps.
|
|
Gods don't kill people - people with Gods kill people.
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Nov 1999
Status:
Offline
|
|
Thanks for all your help! I do have a few more questions though.
In the script editor I typed the code you gave above:
tell application "Finder"
set theApps to name of every application process whose visible is true
repeat with anApp in theApps
try
if anApp * "Finder" then
tell application anApp
quit
end tell
end if
end try
end repeat
end tell
I tried to run the script but it didn't work. It seemed to do something, but none of the applications quit. I was thinking, do I need to add something else to get the running apps, or is "set theApps to name of every application process whose visible is true" enough information?
The other thing that I thought might be causing the problem is that "anApp" was never set to anything. Does it need to be or is it part of a dictionary (couldn't find it in the finder dictionary). Just seeing if I could figure out what the problem is. Maybe it is something else, I am new at all of this.
Also I haven't been able to find the Script Scheduler in Mac OS9. I checked my HD and the software install CD. I did find iDo on the OS9 software install CD. I guess I'll use that, unless there is some advantage to the OS9 scheduler (in which case I need to go and find it).
Once again, thanks.
|
|
|
| |
|
|
|
 |
|
 |
|
Bob W.
|
|
Launch Key can easily do this and a whole lote more, without having to write a line of AppleScript.
http://www.trivectus.com/
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 1999
Location: Georgetown, Demerara, Guyana
Status:
Offline
|
|
Hi ussfolsom,
I hope you've already found your answers by now (or that you've have been in e-mail contact with Camelot)... Just wanted to mention that I believe that the answers to many of your questions were already there in his post. In brief:- - As was mentioned in the original comment that appeared above the 'if anApp * "Finder"' statement, don't actually type '*'; instead, hold down the option-key and type '=' (to get the "not equal" sign).
- The 'anApp' variable is being implicitly set to different values by the 'repeat with anApp in theApps' statement. Each successive iteration through the repeat-loop will set 'anApp' to the name of the "next" open program.
- The 'Script Scheduler' and the 'iDo' are one and the same program; it's made by Sophisticated Circuits. There is no built-in Mac OS script scheduler, so instead Apple distributes the "lite" version of the 'iDo Script Scheduler' program on the Mac OS 9.x CD-ROM. [Update: For anyone else who might be reading this and doesn't have access to a Mac OS 9.x CD-ROM, 'iDoSS' is also distributed on the Mac OS 8.6 CD-ROM. And, as Camelot indicated above, it's also available online directly from Sophisticated Circuits' download page, or via Apple's AppleScript Extras package].
In addition, if you prefer not to use AppleScript, there are various shareware/commercial utilities available which I believe can perform the tasks that you described; the amount of code-writing required varies among them. These utilities include TriVectus' Launch Key (as Bob W. mentioned in his post above), CE Software's QuicKeys, WestCode Software's OneClick, Prefab Software's Player, Binary Software's KeyQuencer (together with Lindsey Dubb's free KeyQuencer extensions), and many others. More complete lists of such utilities can be obtained at online software directories like Pure Mac's Launchers and System Enhancements lists; or, by querying software search-engines like VersionTracker or Apple's Macintosh Products Guide. You could scan the directory list, or query the search engine, for strings/keywords like 'automate', 'automation', 'hot key' and/or 'macro', etc.
Regards,
--Paul
[This message has been edited by Paul Crawford (edited 11-01-2000).]
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 1999
Location: Georgetown, Demerara, Guyana
Status:
Offline
|
|
Hi all,
Just wanted to note that there is another possibile snag with the "quit all running applications" script shown above... Recent versions of AppleScript (1.4.x) seem to be affected by a bug where nested application commands can be mistakenly sent to the outermost target app instead of to the innermost target app; in other words, the script shown above might actually quit the Finder instead of the other programs! For instance, see the later related thread, simple applescript question, in this Forum.
Regards,
--Paul
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|