|
|
#1 |
|
Prospect
Join Date: Sep 2004
Posts: 9
|
AppleScript with System Preferences...?
i just started looking at AppleScript with an eye towards making some simple System Preferences scripts, and have immediately run in to a snag. the following will work with any application i have except System Preferences:
tell application "app name" launch end tell When i try the above with System Preferences i get a notice saying "Syntax Error: application isn't running". help? |
|
|
|
|
|
#2 |
|
MVP
Join Date: Apr 2004
Location: Cumbria, UK
Posts: 2,461
|
LESSON 1: The Correct Use of The Activate Command And Launch Command (to be read in a John Cleese TV announcer voice)
"Activate" should be used to launch applications with a GUI, or bring them to the front of the screen if they have already been launched. Examples are all the well known ones i.e iPhoto and including System Preferences.app "Launch" should be used to launch applications that do not have a GUI. i.e. Image Events.app You can often use them interchangeably but I understand that problems can occur if you don't get it right. I guess that's what's happened in this case. |
|
|
|
|
|
#3 |
|
Prospect
Join Date: Sep 2004
Posts: 9
|
ah, thank you. can you give me a couple more tips? i want to write 2 scripts which will enable me to toggle between the Highest and Automatic settings in the Processor Performance menu of the Energy Saver. here's what i've got -the things in parenthesis are commands i don't know the proper syntax for.
tell application "System Preferences" activate end tell tell application "System Events" tell application process "System Preferences" set frontmost to true click menu item "Energy Saver" of menu "View" of menu bar 1 tell window "Energy Saver" (click the "Options" tab) (choose "highest" from the processor performance menu) end tell end tell end tell end tell
__________________
using: PowerBook 12", 1.33 GHz, 768 MB RAM, OS 10.3.5 |
|
|
|
|
|
#4 |
|
MVP
Join Date: Apr 2004
Location: Cumbria, UK
Posts: 2,461
|
GUI scripting (which is what the script you have posted is) isn't really Applescript - it works (half the time), but it's primary purpose is allow complex Applescripts written in XCode to control the user interfaces of other applications.
For running simple scripts i.e. written in Script Editor, GUI scripting doesn't work well. It's buggy, scripts frequently break (there is about a 50/50 chance that when 10.3.6 arrives a script working on System Preferences will stop working) and often you simply cannot do what you want to do. The general rule is that if you find yourself writing GUI scripts in Script Editor (and in IMO Xcode) then it's because you haven't yet found a better way of doing it ..... .... and that rule applies with your script. There is currently a thread on Apple Discussions that covers this very query, which bypasses System Preferences altogether here. |
|
|
|
|
|
#5 |
|
Prospect
Join Date: Sep 2004
Posts: 9
|
brilliant - thank you. the script there works exactly as i hoped.
a question: what exactly does the "Automatic" setting do in the Processor Performance menu? Does it toggle between Highest and Reduced based on demand, or is it not quite that simple? cheers, j
__________________
using: PowerBook 12", 1.33 GHz, 768 MB RAM, OS 10.3.5 |
|
|
|
|
|
#6 | |||||||||||||||||||||||
|
MVP
Join Date: Apr 2004
Location: Cumbria, UK
Posts: 2,461
|
I'm sorry but my G4 don't make use of these settings - so I don't know. Maybe posting the request under the system forum will get a better response. |
|||||||||||||||||||||||
|
|
|
|
|
#7 |
|
Prospect
Join Date: Nov 2004
Posts: 3
|
could you please post the script as the discussion page seems to have disappeared
thanks |
|
|
|
|
|
#8 |
|
Prospect
Join Date: Sep 2004
Posts: 9
|
hm - i don't have the original script anymore, just a compiled little applet. since the source code includes my password, i don't want to post it, but if you can tell me how to get AppleScript code out of a compiled applet then i'll gladly post what there is to post.
__________________
using: PowerBook 12", 1.33 GHz, 768 MB RAM, OS 10.3.5 |
|
|
|
|
|
#9 |
|
Prospect
Join Date: Nov 2004
Posts: 3
|
i believe that unless you have made the script read-only, you can open it in script editor to see the script's code. however, if the script is read only, i do not know how you can pull out the code. one question though, did you use the pmset command because i found that on another discussion at apple's support forums.
|
|
|
|
|
|
#10 |
|
Prospect
Join Date: Nov 2004
Posts: 5
|
couldn't you open the script in a editor such as SubEthaEdit? im not sure though :P
|
|
|
|
|
|
#11 |
|
Prospect
Join Date: Nov 2004
Posts: 3
|
i just tried to open a read only script in subethaedit, it shows (what looks like to me) a lot of jibberish, but i think that someone who knew a little bit more than i do could figure out what the script's purpose is, but not the original applescript code (that last part is speculation)
|
|
|
|
|
|
#12 |
|
Triple-A Player
Join Date: Jun 2004
Posts: 77
|
A script that's saved as an application _WITHOUT_ the "Run Only" checkbox can be opened in Script Editor and you can view or edit it's source. You'll have to use File->Open or drag the applet onto Script Editor's icon (since if you try to double-click the Applet it will simply execute).
However, if it's been saved as an application _AND_ the "Run Only" checkbox was checked you can't recover the source code... Script Editor will just give you an empty window. |
|
|
|
![]() |
|
|