Posted on 07-26-2021 12:08 PM
Hey All -
I'm trying to get the icon that we utilize for our Self Service portal (located at /Library/Application Support/com.jamfsoftware.selfservice.mac/Documents/Images) to display when calling a custom "Display Dialog" AppleScript popup from within a Bash script.
Current code looks like:
#!/bin/bash
#get logged in user info
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
loggedInUserUID=$(id -u "$loggedInUser")
userPopup="set input to \
(display dialog \
\"blah blah blah\" \
with title \"xxxxxx\" \
with icon POSIX file \"/Library/Application Support/com.jamfsoftware.selfservice.mac/Documents/Images/brandingimage_asTest.icns\")"
prompt=$( /bin/launchctl asuser $loggedInUserUID sudo -u "$loggedInUser" /usr/bin/osascript -e "$userPopup" )
which errors out with this:
execution error: Can’t make file "Macintosh HD:Library:Application Support:com.jamfsoftware.selfservice.mac:Documents:Images:brandingimage_asTest.icns" into type number or string. (-1700)
However, if I copy the same file to the Desktop and run this code snippet, it works perfectly:
#!/bin/bash
#get logged in user info
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
loggedInUserUID=$(id -u "$loggedInUser")
userPopup="set input to \
(display dialog \
\"blah blah blah\" \
with title \"xxxxxx\" \
with icon POSIX file \"/Users/<username>/Desktop/brandingimage_asTest.icns\")"
prompt=$( /bin/launchctl asuser $loggedInUserUID sudo -u "$loggedInUser" /usr/bin/osascript -e "$userPopup" )
I should also mention I have tried both methods without specifying POSIX file and utilizing normal AppleScript method and the same behavior occurs.
Does anyone know a way to make this work while utilizing a non-user filepath? Or is this just a pitfall of using apple script?
Solved! Go to Solution.
Posted on 07-26-2021 04:20 PM
So, the end results of that path is a mix of POSIX and non-POSIX, which won't work. AppleScript doesn't understand UNIX pathing, so we probably need to convert the tilde to a path and then concatenate it and the rest of the path.
set homePath to do shell script "echo $HOME"
-- e.g. "/Users/talkingmoose"
display dialog "blah blah blah" with title "Blah Title" with icon POSIX file (homePath & "/Library/Application Support/com.jamfsoftware.selfservice.mac/Documents/Images/brandingimage.png" as string)
-- e.g. "/Users/talkingmoose/Library/Application Support/com.jamfsoftware.selfservice.mac/Documents/Images/brandingimage.png"
See if that gets you what you need.
Posted on 07-26-2021 01:19 PM
See if this snippet helps. Replace my path with yours.
#!/bin/bash
theCommand='display dialog "blah blah blah" with title "Blah Title" with icon posix file "/Applications/Self Service.app/Contents/Resources/AppIcon.icns"'
/usr/bin/osascript -e "$theCommand"
This is a great way to cleanly spell out the entire one-line AppleScript command without having to escape so many quotes.
Posted on 07-26-2021 01:29 PM
Thanks for the reply! Definitely cleaner than mine, so I appreciate that.
This works, however, that AppIcon.icns file is the generic Jamf logo for Self-Service. I'm looking to apply our custom self service icon, which to my knowledge is only found in "/Library/Application Support/com.jamfsoftware.selfservice.mac/Documents/Images". Is there another area within the /Applications/Self Service.app/Contents directory that the custom icon might live?
Thank you!
Posted on 07-26-2021 01:42 PM
If you navigate to the directory you mention, do you actually see it there? The custom branding images should live in the end user's home folder "~/Library/Application Support/com.jamfsoftware.selfservice.mac/Documents/Images/brandingimage.png" not the top level Library folder.
Posted on 07-26-2021 01:58 PM
Yes, I see the custom company icon in both areas - both the public /Library/Application Support/ filepath as well as the user ~/Library/application support folder. I'm getting a specific apple script error using these paths:
execution error: Can’t make file ":~:Library:Application Support:com.jamfsoftware.selfservice.mac:Documents:Images:brandingimage_asTest.icns" into type number or string. (-1700)
Posted on 07-26-2021 04:20 PM
So, the end results of that path is a mix of POSIX and non-POSIX, which won't work. AppleScript doesn't understand UNIX pathing, so we probably need to convert the tilde to a path and then concatenate it and the rest of the path.
set homePath to do shell script "echo $HOME"
-- e.g. "/Users/talkingmoose"
display dialog "blah blah blah" with title "Blah Title" with icon POSIX file (homePath & "/Library/Application Support/com.jamfsoftware.selfservice.mac/Documents/Images/brandingimage.png" as string)
-- e.g. "/Users/talkingmoose/Library/Application Support/com.jamfsoftware.selfservice.mac/Documents/Images/brandingimage.png"
See if that gets you what you need.
Posted on 07-27-2021 12:34 PM
This worked! What a champion - thank you so much for the help.