Hello everyone,
I'm looking for help deploying AppleScript through Jamf Pro. I know the basics of bash scripts but almost nothing about AppleScript. I got the following AppleScript from one of our network administrators:
tell application "System Events"
set macUser to name of current user
end tell
try
set FortiDir to POSIX file "/Users/Shared/Fortinet/Forticlient"
set ztnaConfig to POSIX file "/Users/Shared/Fortinet/Forticlient/ztnaconfig.json"
set FortiDir to POSIX path of the file FortiDir
set ztnaConfig to POSIX path of the file ztnaConfig
do shell script "chown -R " & macUser & " " & FortiDir with administrator privileges
do shell script "chmod 755 " & FortiDir with administrator privileges
do shell script "chmod 644 " & ztnaConfig with administrator privileges
display dialog "BW FortiClient permissions patch successful"
on error theErr
display dialog "File permissions update failed for " & FortiDir
end try
I tried to deploy it as a shell script in Jamf like this:
#!/bin/bash
osascript -e 'tell application "System Events"
set macUser to name of current user
end tell
try
set FortiDir to POSIX file "/Users/Shared/Fortinet/Forticlient"
set ztnaConfig to POSIX file "/Users/Shared/Fortinet/Forticlient/ztnaconfig.json"
set FortiDir to POSIX path of the file FortiDir
set ztnaConfig to POSIX path of the file ztnaConfig
do shell script "chown -R " & macUser & " " & FortiDir with administrator privileges
do shell script "chmod 755 " & FortiDir with administrator privileges
do shell script "chmod 644 " & ztnaConfig with administrator privileges
display dialog "BW FortiClient ZTNA permissions patch successful"
on error theErr
display dialog "File permissions update failed for " & FortiDir
end try'
It works on some machines but fails on others. The error is:
Script result: 56-60: execution error: System Events got an error: Application isn't running. (-600)
I searched for the error and found out a line to launch System Events by adding this:
tell application "System Events"
set macUser to name of current user
end tell
try
set FortiDir to POSIX file "/Users/Shared/Fortinet/Forticlient"
set ztnaConfig to POSIX file "/Users/Shared/Fortinet/Forticlient/ztnaconfig.json"
set FortiDir to POSIX path of the file FortiDir
set ztnaConfig to POSIX path of the file ztnaConfig
do shell script "chown -R " & macUser & " " & FortiDir with administrator privileges
do shell script "chmod 755 " & FortiDir with administrator privileges
do shell script "chmod 644 " & ztnaConfig with administrator privileges
display dialog "BW FortiClient permissions patch successful"
on error theErr
display dialog "File permissions update failed for " & FortiDir
end try'
I still get errors, and this post is getting too long to post them. I think it's possible that I'm messing up the syntax when integrating AS into shell. I'm hoping it's something very simple that one of you can spot easily.
Appreciate your time and suggestions.