Possible I am missing the point, but can't you Export the profile as a .terminal
file and add that to your Login Items?
Export:
Add the exported file to Login Items:
In my environment the script works as expected. I used a different name for the generic key though: boot_key
The attributes of boot_key:
The password is self-evidently also klanomath's login password. security is always allowed to use the key!
To debug the Apple script enable "Show Log" with cmd3
The script:
display dialog "Select a startup disk" buttons ¬
{"BOOTCAMP", "Macintosh HD"}
if button returned of the result = "BOOTCAMP" then
set bootVol to "BOOTCAMP" as text
else if button returned of the result = "Macintosh HD" then
set bootVol to "Macintosh HD" as text
end if
do shell script "security 2>&1 >/dev/null find-generic-password -gl \"boot_key\" | awk '{print $2}'"
set myPass to (text 2 thru -2 of result) as text
do shell script "bless -mount \"/Volumes/" & bootVol & ¬
"\" -setBoot" user name "klanomath" password myPass with administrator privileges
do shell script "echo \"shutdown -r now\"" user name "klanomath" password myPass with administrator privileges
will then reveal - after choosing "Macintosh HD" - in the "Replies" part:
tell application "Script Editor"
display dialog "Select a startup disk" buttons {"BOOTCAMP", "Macintosh HD"}
--> {button returned:"Macintosh HD"}
end tell
tell current application
do shell script "security 2>&1 >/dev/null find-generic-password -gl \"boot_key\" | awk '{print $2}'"
--> "\"Passw0rd\""
do shell script "bless -mount \"/Volumes/Macintosh HD\" -setBoot" user name "klanomath" password "Passw0rd" with administrator privileges
--> ""
do shell script "echo \"shutdown -r now\"" user name "klanomath" password "Passw0rd" with administrator privileges
--> "shutdown -r now"
end tell
Result:
"shutdown -r now"
You may log various variables explicitly by adding log $variable
lines (which is redundant with the "Replies" in some cases):
display dialog "Select a startup disk" buttons ¬
{"BOOTCAMP", "Macintosh HD"}
if button returned of the result = "BOOTCAMP" then
set bootVol to "BOOTCAMP" as text
else if button returned of the result = "Macintosh HD" then
set bootVol to "Macintosh HD" as text
end if
log bootVol
do shell script "security 2>&1 >/dev/null find-generic-password -gl \"boot_key\" | awk '{print $2}'"
set myPass to (text 2 thru -2 of result) as text
log myPass
do shell script "bless -mount \"/Volumes/" & bootVol & ¬
"\" -setBoot" user name "klanomath" password myPass with administrator privileges
log bootVol
log myPass
do shell script "echo \"shutdown -r now\"" user name "klanomath" password myPass with administrator privileges
log myPass
which then reveals:
tell application "Script Editor"
display dialog "Select a startup disk" buttons {"BOOTCAMP", "Macintosh HD"}
--> {button returned:"Macintosh HD"}
end tell
(*Macintosh HD*)
tell current application
do shell script "security 2>&1 >/dev/null find-generic-password -gl \"boot_key\" | awk '{print $2}'"
--> "\"Passw0rd\""
(*Passw0rd*)
do shell script "bless -mount \"/Volumes/Macintosh HD\" -setBoot" user name "klanomath" password "Passw0rd" with administrator privileges
--> ""
(*Macintosh HD*)
(*Passw0rd*)
do shell script "echo \"shutdown -r now\"" user name "klanomath" password "Passw0rd" with administrator privileges
--> "shutdown -r now"
(*Passw0rd*)
end tell
or as a screenshot:
Now you should be able to detect the error in your script or your environment.
Best Answer
Command line programs can be run using the
do shell script "..."
command in AppleScript. You can generally write a command as you would in Terminal, keeping in mind that double quotes need to be escaped with a preceding backslash\
. Thedo shell script
command returns the last output tostdout
.So, for example:
will return
hello world
as a string.These commands are run without a terminal, so can't interact with the user, e.g. to receive user input. If you need a terminal, you can
tell application "Terminal" to tell the front window to tell the front tab to do script "..."
.But,
do shell script "..."
is perfect for most situations where bash commands need to be employed.If it's useful to know, iTunes can also play audio streams from the internet. You can do this from the command line like this:
From within AppleScript, this might look like:
or, using iTunes scriptability: