Preview - add Signature by key command. Find Menu name
On the face of it, this seems an impossible task.
You can add a key command to any menu item, but first you need the precise wording for that item. This makes contextual menu items difficult, but not impossible, to add commands to.
A Signature in the menu, on the other hand, has no visible wording. It's a thumbnail image.
Therefore, it would appear that in order to add a key command, we must first find the name of that item… if it has one.
Does anyone have a method to discover that name, should it exist?
Solution 1:
"Does anyone have a method to discover that name, should it exist?"
In Preview using Accessibility Inspector, a part of Xcode, the properties of a the menu item that is the image of the signature shows as: AXTitle <empty string>
If you do not have Xcode installed, you can also get the properties of the target menu item in Script Editor with the example AppleScript code shown below by changing click ¬
to return properties of ¬
, and on my system it returned title:""
and name:missing value
for those two particular properties.
Alternate Solution
As any keyboard shortcut you'd assign has to be unique to the target application, why not just use an Automator Quick Action/Service assigned that keyboard shortcut and use the following example Automator Quick Action/Service to achieve the goal of being able to apply a signature in Preview:
Use the following example AppleScript code in an Automator Quick Action/Service configured as show in the image below.
I used ⌃⌥⌘S for the keyboard shortcut assigned to it in: System Preferences > Keyboard > Shortcuts > Services
Example AppleScript code:
tell application "System Events" to ¬
click ¬
menu item 1 of ¬
menu 1 of ¬
menu item "Signature" of ¬
menu 1 of ¬
menu item "Annotate" of ¬
menu 1 of ¬
menu bar item "Tools" of ¬
menu bar 1 of ¬
application process "Preview"
Notes:
The example AppleScript code, shown above, was tested in as an Automator Quick Action/Service under macOS Catalina with Language & Region settings in System Preferences set to English (US) — Primary and worked for me without issue1.
- 1 Assumes necessary and appropriate settings in System Preferences > Security & Privacy > Privacy have been set/addressed as needed.
Replace the default code of the Run AppleScript action with the example AppleScript code.
Localization of the example AppleScript code may be necessary for other languages/regional settings.
The example AppleScript code as currently coded assumes only one signature exists in the menu hierarchy. The menu item 1 of
following click ¬
can be changed to a different value as needed.
Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5
, with the value of the delay set appropriately.