Skip to main content
Solved

Get Custom Icon to show in AppleScript Dialog Box


Forum|alt.badge.img+6

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?

Best answer by talkingmoose

jrogersnh wrote:

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)

 

 


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.

View original
Did this topic help you find an answer to your question?

6 replies

talkingmoose
Forum|alt.badge.img+36
  • Community Manager
  • 1900 replies
  • July 26, 2021

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.


Forum|alt.badge.img+6
  • Author
  • Contributor
  • 13 replies
  • July 26, 2021
talkingmoose wrote:

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.


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!


talkingmoose
Forum|alt.badge.img+36
  • Community Manager
  • 1900 replies
  • July 26, 2021
jrogersnh wrote:

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!


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.


Forum|alt.badge.img+6
  • Author
  • Contributor
  • 13 replies
  • July 26, 2021
talkingmoose wrote:

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.


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)

 

 


talkingmoose
Forum|alt.badge.img+36
  • Community Manager
  • 1900 replies
  • Answer
  • July 26, 2021
jrogersnh wrote:

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)

 

 


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.


Forum|alt.badge.img+6
  • Author
  • Contributor
  • 13 replies
  • July 27, 2021
talkingmoose wrote:

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.


This worked! What a champion - thank you so much for the help. 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings