Expected end of line but found “"” from Applescript

I want to do the next step by whether the program menu is enabled or not, so I detect it by Applescript, but it gives me an error: Expected end of line but found “"”

tell application "BetterTouchTool"
    tell application "System Events"
        tell application process "Adobe Audition CC 2017"
            if menu item "Cut" of menu "Edit" of menu bar item "Edit" of menu bar 1 is enabled then
                trigger_named_async_without_response "draw_ink"
            else
                trigger_named_async_without_response "highlighter"
            end if
        end tell
    end tell
end tell

What I Missed

This is the complete UI elements

menu item "Cut" of menu "Edit" of menu bar item "Edit" of menu bar 1 of application process "Adobe Audition CC 2018" of application "System Events"

Can you help me?@Andreas_Hegenberg
I searched for a long time on the Internet.

I don't have "Adobe Audition CC 2017", but the AppleScript syntax must be like this for it to work:

tell application "System Events"
	tell application process "Adobe Audition CC 2017"
		if menu item "Cut" of menu "Edit" of menu bar item "Edit" of menu bar 1 is enabled then
			tell application "BetterTouchTool"
				trigger_named_async_without_response "draw_ink"
			end tell
		else
			tell application "BetterTouchTool"
				trigger_named_async_without_response "highlighter"
			end tell
		end if
	end tell
end tell
1 Like

Thank you for your reply.

It works.

Maybe there is something wrong with my script, it can only run one of the results. "is enabled" action is not recognized. In order to make it clearer, I changed "Adobe Audition CC 2017" to "Notes", the program that comes with Apple

tell application "System Events"
	tell application process "Notes"
		if menu item "Cut" of menu "Edit" of menu bar item "Edit" of menu bar 1 is enabled then
			tell application "BetterTouchTool"
				trigger_named_async_without_response "draw_ink"
			end tell
		else
			tell application "BetterTouchTool"
				trigger_named_async_without_response "highlighter"
			end tell
		end if
	end tell
end tell
[
  {
    "BTTAppBundleIdentifier" : "com.apple.Notes",
    "BTTAppName" : "Notes",
    "BTTAppAutoInvertIcon" : 1,
    "BTTAppProcessMatchMode" : 2,
    "BTTAppProcessName" : "Notes",
    "BTTTriggers" : [
      {
        "BTTTriggerType" : 179,
        "BTTTriggerTypeDescription" : "2 Finger Double-Tap",
        "BTTTriggerClass" : "BTTTriggerTypeTouchpadAll",
        "BTTPredefinedActionType" : 195,
        "BTTPredefinedActionName" : "Run Apple Script (async in background)",
        "BTTInlineAppleScript" : "tell application \"System Events\"\r\ttell application process \"Notes\"\r\t\tif menu item \"Cut\" of menu \"Edit\" of menu bar item \"Edit\" of menu bar 1 is enabled then\r\t\t\ttell application \"BetterTouchTool\"\r\t\t\t\ttrigger_named_async_without_response \"draw_ink\"\r\t\t\tend tell\r\t\telse\r\t\t\ttell application \"BetterTouchTool\"\r\t\t\t\ttrigger_named_async_without_response \"highlighter\"\r\t\t\tend tell\r\t\tend if\r\tend tell\rend tell",
        "BTTEnabled2" : 1,
        "BTTAlternateModifierKeys" : 0,
        "BTTRepeatDelay" : 0,
        "BTTUUID" : "0C551E2E-FECD-4748-8DE1-135ED3CC2C33",
        "BTTNotesInsteadOfDescription" : 0,
        "BTTEnabled" : 1,
        "BTTModifierMode" : 0,
        "BTTOrder" : 0,
        "BTTDisplayOrder" : 0
      },
      {
        "BTTTriggerType" : 643,
        "BTTTriggerTypeDescription" : "Named Trigger: highlighter",
        "BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
        "BTTPredefinedActionType" : -1,
        "BTTPredefinedActionName" : "No Action",
        "BTTLayoutIndependentActionChar" : "LEFT",
        "BTTAutoAdaptActionToKeyboardLayout" : true,
        "BTTShortcutToSend" : "58,123",
        "BTTTriggerName" : "highlighter",
        "BTTEnabled2" : 1,
        "BTTAlternateModifierKeys" : 0,
        "BTTRepeatDelay" : 0,
        "BTTUUID" : "9886CF84-B6E1-4699-A745-8DCA11A68B59",
        "BTTNotesInsteadOfDescription" : 0,
        "BTTEnabled" : 1,
        "BTTModifierMode" : 0,
        "BTTOrder" : 2,
        "BTTDisplayOrder" : 0
      },
      {
        "BTTTriggerType" : 643,
        "BTTTriggerTypeDescription" : "Named Trigger: draw_ink",
        "BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
        "BTTPredefinedActionType" : -1,
        "BTTPredefinedActionName" : "No Action",
        "BTTLayoutIndependentActionChar" : "DELETE",
        "BTTAutoAdaptActionToKeyboardLayout" : true,
        "BTTShortcutToSend" : "51",
        "BTTTriggerName" : "draw_ink",
        "BTTEnabled2" : 1,
        "BTTAlternateModifierKeys" : 0,
        "BTTRepeatDelay" : 0,
        "BTTUUID" : "E97F0987-E53B-441B-98DF-1E34EE222810",
        "BTTNotesInsteadOfDescription" : 0,
        "BTTEnabled" : 1,
        "BTTModifierMode" : 0,
        "BTTOrder" : 1,
        "BTTDisplayOrder" : 0
      }
    ]
  }
]

The "enabled" property of the menu item is not always updated. Therefore it is better to query the value of the attribute. Try this:

tell application "System Events"
	tell application process "Notes"
		if (value of attribute "AXEnabled" of menu item "Cut" of menu "Edit" of menu bar item "Edit" of menu bar 1) is true then
			tell application "BetterTouchTool"
				trigger_named_async_without_response "draw_ink"
			end tell
		else
			tell application "BetterTouchTool"
				trigger_named_async_without_response "highlighter"
			end tell
		end if
	end tell
end tell

Note: The value of attribute "AXEnabled" is always „false" if the application is not active. The script can therefore only be tested meaningfully in the Script Editor with a "delay" (e.g. 5 seconds) at the beginning of the script and the switch to the application during execution.

1 Like

Nice! It works very well. Thank you very much.