views:

110

answers:

1

I would like to make sure that an applescript can be converted to bash. Are there any ideas on how to do this? And if so, I'll place a simple applescript below to give you an example of how the script runs. In more clarity, I simply want a bash script or shell script to do what my applescript is doing. I want it to "enable" or change the default of the switch in system preferences, under "energy saver" that reads ...'start up automatically after a power failure'...:

set uiScript to "click checkbox \"Start up automatically after a power failure\" of list 2 of group 1 of window \"Energy Saver\" of application process \"System Preferences\""

run script "tell application \"System Events\" " & uiScript & " end tell"

  • any ideas on how to convert this script?

Thanks, -Unimachead

+4  A: 

You may not actually need to convert it - you can run AppleScript from within a bash script, using osascript.

$ man osascript

Note that you can run AppleScript either from a file or just include the source on the command line.

Paul R
I'll give it a try. So in essence at the command prompt, all I need to do is the following?:on run argv return "set uiScript to "click checkbox \"Start up automatically""."end run
Unimachead
Not quite - you need to use `osascript`, i.e. `osascript -e "<your AppleScript>"`
Paul R
Got it. I could make this into a unix executable and sudo it via terminal so that it will to recognize any scripts with similarity. Possibly?
Unimachead
You could - although if it's just a one-liner then you can just keep it as simple shell script which you can run from the Terminal.
Paul R
Super. I'll give it a go. This is something I'd like to bake into the image I'm working on, so that the commands to do things such as what I've built via applescript will be executed each time I'm authenticating into the machine.
Unimachead
Apparently I'm not making proper placement with the applescript to run correctly after osascript. Thoughts?
Unimachead
Suggest you post your script so far as a new question here on SO and then we can get it debugged.
Paul R