06-16-2023 01:27 AM - edited 06-16-2023 01:29 AM
Hello All,
Need your help, i have Apple script which will update the macOS for both Intel and M1 and restart if it's M1 it will prompt for the user password to install macOS. now it's working fine when i run from Apple script editor.
But i need to convert the Apple script to run as bash script so that we can push from JAMF.
=========================================================================================
# Launch software Update preference pane
do shell script "open x-apple.systempreferences:com.apple.Software-Update-Settings.extension"
tell application "System Events"
repeat 60 times
if exists (window 1 of process "System Settings") then
delay 3
exit repeat
else
delay 1
end if
end repeat
if not (exists (window 1 of process "System Settings")) then
return
end if
end tell
# Click "Update Now" or "Restart Now" if present
tell application "System Events"
tell process "System Settings"
repeat 60 times
if exists (button 1 of group 2 of scroll area 1 of group 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Software Update" of application process "System Settings" of application "System Events") then
click button 1 of group 2 of scroll area 1 of group 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Software Update" of application process "System Settings" of application "System Events"
exit repeat
end if
tell application "System Events"
if application process "System Settings" exists then
delay 0.5
else
exit repeat
end if
end tell
delay 1
end repeat
tell application "System Events"
if application process "System Settings" exists then
delay 0.5
else
exit repeat
end if
end tell
delay 1
end tell
end tell
end
Posted on 06-16-2023 02:17 AM
Hello jGan,
To convert the AppleScript into a Bash script, you can use the osascript command-line tool, which allows you to execute AppleScript commands from the command line
Posted on 06-16-2023 03:26 AM
@Jaykrishna1 I can run from CLI as you said, but i want push from Jamf as bash script.
Posted on 06-16-2023 04:03 AM
I think he means it in a way that you can write something like this in your script:
osascript << EndOfScript
some applescript code
EndOfScript
We are also using this to sometimes include Applescripts into our normal shell scripts
Posted on 06-16-2023 05:50 AM
@Ismere Yes, But i am not good in scripting, and i am not sure how add that osacript this in above apple script😬
Posted on 06-16-2023 06:04 AM
Ah ok yeah that is no Problem at all.
You just write your normal script and then add all of your osascript into the Lines between the two EndOfScript keys. Eventually you may wantmto move the open part into the normal shell script area, since you are starting in shell and temporaly switching over to osa. which would be something like this:
#!/bin/bash
open x-apple.systempreferences:com.apple.Software-Update-Settings.extension
osascript << EndOfScript
the rest of your apple script copied straight from your editor
EndOfScript
exit 0
06-16-2023 08:41 AM - edited 06-16-2023 08:45 AM
@IsmereThank You. i have did same but i am getting an error, and if i run without sudo system setting is opening. I think script should as current login user
=========================================================================
The application cannot be opened for an unexpected reason, error=Error Domain=RBSRequestErrorDomain Code=5 "Launch failed." UserInfo={NSLocalizedFailureReason=Launch failed., NSUnderlyingError=0x600003080570 {Error Domain=OSLaunchdErrorDomain Code=125 "Domain does not support specified action" UserInfo={NSLocalizedFailureReason=Domain does not support specified action}}}
===========================================================================
Posted on 06-23-2023 03:38 AM
Scripting OSX posted a good way to run scripts or at least parts of it as a logged in User.
You can read about it following this link :
https://scriptingosx.com/2020/08/running-a-command-as-another-user/