Apple Script Error

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Apple Script Error Fri May 27, 2022 8:18 am • by DoogieWall
Good morning everyone. I'm trying to create a hazel automation to change a new folder image. I found an apple script on the Automators forum that asks for a icon and folder location. This works on my machine. I modified the script so it has a fixed icon to use and takes thefile parameter in hazel. When I run the modified script in hazel I get an error.

The script is as follows:

set iconFolder to (path to home folder as text) & "Dropbox:cllc:icons:yosemiteICNS" -- Location of your icns files
set icon to (path to home folder as text) & "Dropbox:CLLC:Icons:YosemiteICNS:Book Bottom.icns"
set Destination to theFile --choose folder with prompt "Please choose the Folder to change "
set destPath to POSIX path of Destination
set sourcePath to POSIX path of icon

set imageData to (current application's NSImage's alloc()'s initWithContentsOfFile:sourcePath)
(current application's NSWorkspace's sharedWorkspace()'s setIcon:imageData forFile:destPath options:2)

The error hazel gives is:

NSImage doesn't understand the "alloc" message.

Any help would be greatly appreciated. Seems like I am so close but so far.
DoogieWall
 
Posts: 6
Joined: Thu Jun 27, 2019 3:28 pm

Re: Apple Script Error Fri May 27, 2022 9:12 am • by Mr_Noodle
I believe you need something like this at the top:
Code: Select all
use framework "AppKit"
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Apple Script Error Fri May 27, 2022 10:06 am • by DoogieWall
Thanks for the quick tip. The original script I copied did have the following at the top:

use framework "Foundation"
use framework "AppKit"
use scripting additions

When I add those all or anyone hazel gives a compile error saying: Expected "end" but found "use".

If I leave them in and ignore the hazel compile error I still get the original error message.
DoogieWall
 
Posts: 6
Joined: Thu Jun 27, 2019 3:28 pm

Re: Apple Script Error Mon May 30, 2022 8:53 am • by Mr_Noodle
You'll have to use an external script. Embedded scripts are implicitly within a handler so the "use" statements won't work there.
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support