erratic handling of "theFile" in embedded Applescript

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

Moderator: Mr_Noodle

Dear all,

I have an issue to get the Folder name of the currently processed file within an embedded AppleScript.
The purpose of the script is to create a new Apple Note with "theFile" as attachment, using the Mac Folder Name as a folder also in Notes.
I basically had the same script running for years for adding those files into Evernote, so I am really puzzled why I face issues now while testing the new script with Notes...
I also do not know, if it is an issue with Hazel (not handling "theFile" properly during my intensive testing?), or with Applescript itself.

The relevant line in the script is the following:
Code: Select all
tell application "Finder"
   set ParentFolder to (name of container of theFile) as string
end tell

Here is the issue: sometimes ParentFolder is empty, sometimes not (meanwhile, the script directly checks "if length of ParentFolder" is >0.... and throws an error)
I am testing with a pdf file, being dropped into the same folder. After a test run, I delete it again from this folder and drop it again after changing the embedded script.
Using exactly the same source file, it may work (ParentFolder name is correctly set), or may not work (ParentFolder is empty) . It seems that killing hazel / or rebooting makes it work at first, bevor again showing the erratic behavior.
Using other files shows the same phenomenon.

any ideas ?

I just updated to the latest Hazel 5.1.4, running on a Mac mini with latest macOS 12.5.1

Thanks in advance !
olisba
 
Posts: 2
Joined: Fri Aug 26, 2022 1:48 pm

Have you tried the script outside of Hazel? Also, try outputting what theFile is to double-check.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

The problematic part of the script (getting theFile and it‘s container folder name within the embedded script) worked flawlessly for some years (feeding pdf attachements into new evernote notes in subfolders matching theFile‘s container name).

I am not sure how I could check theFile outside of Hazel - since theFile is provided by Hazel to the embedded script ?

What for sure worked in every test, that theFile was successfully added to a new Apple note… just getting the container folder name of theFile does not work robustly.
olisba
 
Posts: 2
Joined: Fri Aug 26, 2022 1:48 pm

You can put the script in a handler with theFile as an argument then call the handler with an alias to the file. Do you see any pattern to when it fails?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support