4 Replies Latest reply on Jun 29, 2016 2:19 AM by Dirk Becker

    Applescript: Script Menu Actions not calling sub-routines referenced within a handler.

    dylw Level 1

      OK this is driving my nuts, I thought I had a good handle on these handlers , but I guess not.

       

      I am running several scripts I have written via submenus in InDesign. I have, essentially, got the functionality working except it breaks whenever an invoked handler which is attached to a script menu item needs to call a sub-routine. I have attached a sample of the script I am writing below to demonstrate what I mean, go straight down to the bottom "on myMenuAction()" for the tricky area, it completely ignores the second statement because of the referenced sub-routine.

       

      Any help on this will be greatly appreciated by me, and the team that will benefit from this script if I get it running properly.

       

       

      tell application "Adobe InDesign CC 2015"

        --Prepare the Menu Item

        try

        set aMenuAction to script menu action "Menu Action Test"

        on error

        set aMenuAction to make script menu action with properties {title:"Menu Action Test"}

        end try

       

        --Make the event listener attached to the Menu Item created

        tell aMenuAction

        --If the script menu action already existed then remove it and start again

        if (count event listeners) > 0 then

        tell every event listener to delete

        end if

        make event listener with properties {event type:"onInvoke", handler:my myMenuAction}

        end tell

       

        --Draw the Menu in InDesign

        tell menu "$ID/Main"

        --Insert the Menu Name

        try

        set myMenuName to submenu "Menu Test"

        on error

        set myMenuName to make submenu with properties {title:"Menu Test"}

        end try

        --Add all the Menu Actions

        tell myMenuName

        try

        set aMenuActionName to menu item "Menu Action Test"

        on error

        set aMenuActionName to make menu item with properties {associated menu action:aMenuAction}

        end try

        end tell

        end tell

       

      end tell


      on theCurrentDay()

        set TodaysDay to the weekday of the (current date)

        return TodaysDay

      end theCurrentDay

       

      on myMenuAction()

        tell application "Adobe InDesign CC 2015"

       

        display dialog "Hello World" --This works because there is no sub-routine involved

       

        display dialog "Hello World, today is " & my theCurrentDay() --This doesn't work because a sub-routine is called

       

       

        end tell

      end myMenuAction