Page 1 of 1

Applescript opens duplicate sessions of files in application

PostPosted: Thu Mar 25, 2021 6:22 pm
by 80sTherapy
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.

Re: Applescript opens duplicate sessions of files in applica

PostPosted: Fri Mar 26, 2021 9:39 am
by Mr_Noodle
Are you running rules manually? If so, then you are going to cause the rule to run again and again creating the duplicates.

Re: Applescript opens duplicate sessions of files in applica

PostPosted: Fri Mar 26, 2021 9:50 am
by 80sTherapy
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

Re: Applescript opens duplicate sessions of files in applica

PostPosted: Sat Mar 27, 2021 11:28 am
by 80sTherapy
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.