Can't make file or alias .... into type number or string? HELP

Not sure how to reconcile this despite trying numerous different things. I’m using a custom icon with a display dialog. I can easily use a display alert but the custom icon is what I’m going for. As you can see, my image file is in a folder inside Documents but that shouldn’t be factor.

On macOS High Sierra, this works fine:

property folderPath : "SSD:Users:bt:Documents:SWITCH:"
set iconPath to (folderPath) & "keyboard.png"
set theAlertText to "          ‼️ KEYBOARD SWITCHED ‼️
             The Keyboard and all other 
    USB Accessories have been switched
               Press OKAY to Continue"

display dialog theAlertText buttons {"OKAY"} default button "OKAY" with icon alias iconPath

Screen Shot 2024-04-05 at 11.38.31 PM

But when I send it to my other computer with macOS Ventura, I get an error:

Can’t make alias “SSD:Users:bt:Documents:SWITCH:keyboard.png” into type number or string.

How can I get this working on a newer OS?
I’ve changed the file to and from a .icns file, set paths, used property for paths, etc. Nothing works… I have tried several suggestions but everything ends up the same error, regardless if it’s:

icon alias

or

icon file

ANY suggestions would be appreciated!!! TIA

The requirements of your new Ventura environment are different. There is nothing wrong with the display dialog command or AppleScript itself.

The name of the boot drive, the user name, the folder hierarchy that contains the images, and the basics are wrong.

In the first place, when assembling a path, if you specify it as a string from the drive letter, it will be a script that works only in your environment. This is a style of writing that should be avoided.

At the very least, it is AppleScript in the Mac OS X era to find the hierarchy below the path to home with a command and then assemble it with a string.

Furthermore, important images such as those displayed in such dialogs should be placed in the AppleScript document to be executed (which can be stored in bundled documents), and the path to me should be found in the path to the AppleScript document and the path should be constructed from there.

set a to choose file of type {"public.image"}

display dialog "This is a simple test" with icon a

This AppleScript works on Ventura.

スクリーンショット 2024-04-06 16.03.38

1 Like

Okay, I think I understand. Where is your public.image file being stored; a specific bundle or just any bundle of my choosing?

In your AppleScript document, it is.

The AppleScript document contains the . SCPT format, . There are three formats: scptd format (bundle format) and .applescript format (text format).

Here we are saying that we should use the .scptd format and put the image in it.
There are surprisingly many Scripters who don’t understand AppleScript documents in the bundle format, so I’ve wrote a single primer on the bundle format.

スクリーンショット 2024-04-06 16.42.30

1 Like

Apple provides a lot of relative paths independent of the user name and the name of the startup disk.

This points to the folder SWITCH inside the documents folder of the current user. Of course SWITCH must exist.

set iconPath to (path to documents folder as text) & "SWITCH:keyboard.png"
1 Like

thazsar. I tested your script on my Sonoma computer, and it worked fine. Assuming the paths are correct, I don’t see why it wouldn’t work on your Ventura computer.

It’s just a guess, but I have to wonder if the path to the icon on your Ventura computer is still valid. An invalid path does return the error you mention:

You might also try coercing iconPath to an alias in the second line of the script and then changing “alias iconPath” to just “iconPath” in the last line of your script. If nothing else, this might help isolate the issue.

1 Like

Oh my gosh…Now I feel like a complete idiot and a-hole for wasting everyone’s time. I had the files in the wrong location :man_facepalming:. I have my sidebar "Documents’ folder assigned to an external HD for memory reasons. My user-name ‘Documents’ folder is where my real files are stored and I forgot. Thanks for helping everyone. It works perfectly fine…

Should I just delete this topic?!

@StefanK: BTW, I’m honored you replied!!! Your script is what helped complete the project I was trying to make.