Invoking Bookends AppleScript via Service Keyboard Shortcut

Users asking other users for AppleScripts that work with Bookends.
Post Reply
BlattnerRef
Posts: 12
Joined: Tue Jul 04, 2017 9:28 am

Invoking Bookends AppleScript via Service Keyboard Shortcut

Post by BlattnerRef »

Hey folks,

I've written a short and sweet AppleScript to switch from my word processor (Mellel) to Bookends and invoke "Copy Citation and Modifiers." I've pasted it in below. When I run the script from Script Editor or directly within Automator by clicking the "run" button within the "Run AppleScript" command dialog box in Automator, it works fine. I've saved the Automator script as a Quick Action to run within Mellel, and I've defined a keyboard shortcut to invoke the Quick Action.

However, when I use the keyboard shortcut, my workspace shifts to Bookends (so it follows the "activate Bookends" command), but then stops.

Does anyone have any idea why this would happen? I realize this may not be a Bookends-specific question. This might have something more global to do with Quick Actions, the "Run AppleScript" command in Automator, and keyboard shortcuts, but I thought I'd start here.

Thanks,

Bill Blattner

---------

The script:

on run {input, parameters}

activate application "Bookends"
tell application "System Events"
tell process "Bookends"
click menu item "Copy Citation and Modifiers…" of menu 1 of menu bar item "Edit" of menu bar 1
end tell
end tell

return input
end run
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Invoking Bookends AppleScript via Service Keyboard Shortcut

Post by Jon »

What's the Input and parameters for?

When I run this script in Script Debugger I get an error: Failed To Run Script. Logical operator NOT use with other than 1 term

I don't know what that means, either.

When I remove the {input, parameters} and 'return input' it works (the dialog appears, I can fill it out, and the results are inserted into Mellel).

I tried making making a Quick Action in Automator but when I invoked it in Services (in Mellel) nothing happened. So I'm afraid I didn't solve it.

Jon
Sonny Software
BlattnerRef
Posts: 12
Joined: Tue Jul 04, 2017 9:28 am

Re: Invoking Bookends AppleScript via Service Keyboard Shortcut

Post by BlattnerRef »

Ha! What are the input, parameters, and return for? I'm not sure, honestly. I'm new to this. They were in the "Run AppleScript" template that Automator provides.

What's odd about this is that it executes the first command, "activate Bookends." Then it stops.
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Invoking Bookends AppleScript via Service Keyboard Shortcut

Post by Jon »

Those are parameters that you would send to the AppleScript when you run it. In your case you're not doing that. You also don't need to return a value. You're just telling Bookends to show the dialog. Which the script does in my hands when you remove those extraneous things. Why not save the AppleScript from Script Editor as an application and run that?

Jon
Sonny Software
BlattnerRef
Posts: 12
Joined: Tue Jul 04, 2017 9:28 am

Re: Invoking Bookends AppleScript via Service Keyboard Shortcut

Post by BlattnerRef »

I tried that, but I get an error that the scripted app does not have accessibility access. I get that error even though I have it selected in the appropriate panel in the Security and Privacy pane. I notice that in the Automation pane of Security and Privacy, the scripted app only has access to system events, not to Bookends. I'm going to poke around the web and see what I can figure out. I don't see an easy way to change the setting in the Automation panel.
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Invoking Bookends AppleScript via Service Keyboard Shortcut

Post by Jon »

You can't add apps to it, but you can reset AppleEvent permissions in the Terminal using tccutil. It can be very useful to fix macOS mistakes.

https://apple.stackexchange.com/questio ... ermissions

Jon
Sonny Software
BlattnerRef
Posts: 12
Joined: Tue Jul 04, 2017 9:28 am

Re: Invoking Bookends AppleScript via Service Keyboard Shortcut

Post by BlattnerRef »

I will look into that. Thanks!

I just tried a work-around someone on the web suggested: I replaced the UI "click" command with

keystroke "y" using {command down, control down}

and it seems to be working. That wouldn't work, of course, for a menu item without a built-in keystroke to invoke it.
Post Reply