Applescript opens duplicate sessions of files in application

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

Moderator: Mr_Noodle

Hi,

The rule below opens downloaded RTF files, send a copy to my desktop, renames the file and subfolder it is sorted in and finally opens it in Pages.

Image

So far, so good.

The last piece is an Applescript I wrote (from information I gleaned online, I am not a coder) that is meant to turn on Track Changes in Pages. It works well when ran inside Script Editor, but I launch the rule, it keeps opening duplicates of the RTF file in Pages (i.e. filename_2, filename3, etc.) for as long as the original RTF files remains in the Download folder.

Here is the script:

Code: Select all
tell application "Pages"
   activate
   tell application "System Events"
      tell process "Pages"
         click menu item "Track Changes" of menu "Edit" of menu bar 1
      end tell
   end tell
end tell


I know this isn't an AppleScript forum but hope someone could tell me how to fix the problem.

Thanks a lot.


P.S. I saw in a similar thread that the problem could be that the rule "doesn't filter out the output of the script", but to be honest I don't know what that means.
80sTherapy
 
Posts: 6
Joined: Tue Mar 23, 2021 10:01 am

Are you running rules manually? If so, then you are going to cause the rule to run again and again creating the duplicates.
Mr_Noodle
Site Admin
 
Posts: 11226
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

No, I have set so that Hazel runs the rule automatically whenever a matching RTF file lands in the Downloads Folder.


P.S. Hazel gives me an error running the Applescript as it creates duplicates.

When the rule is run manually, no duplicates but same error message when trying to Running the Applescript.

Image
80sTherapy
 
Posts: 6
Joined: Tue Mar 23, 2021 10:01 am

I solved the duplication issue by first moving the processed file to my Documents folder and then copying it to the desktop, however Hazel still returns the same "error executing Applecript" message. That happens with any Applescript and whether the script is embedded or run externally.

EDIT: FIXED. Checked the log and Hazel needed assistive access. Also needed to insert a delay for this particular script to work. I'll go over the others.

Thx.
80sTherapy
 
Posts: 6
Joined: Tue Mar 23, 2021 10:01 am


Return to Support