Shortcut for Preview sketch tool

preview

Nearly every time I open Preview.app I will then immediately press the toolbox button and then the sketch button.

enter image description here

Is there a shortcut to access the sketch tool or some way to put the sketch button on my default toolbar?

Best Answer

This workaround applies to Preview.app 9.0 (909.12) in macOS Sierra 10.12.2 and will most likely break in future releases.

  1. Launch AppleScript Editor and enter the following.

    tell application "System Events" to tell process "Preview"
        activate
        set markup to checkbox 1 of toolbar 1 of window 1
        tell markup
            if not (its value as boolean) then
                click markup
                delay 0.1
            end if
        end tell
        set sketch to checkbox 1 of toolbar 2 of window 1
        tell sketch
            if not (its value as boolean) then
                click sketch
            end if
        end tell
    end tell
    
  2. Launch Preview, open a document, switch back to AppleScript Editor, and run your script. You will most likely get at least one error about AppleScript Editor requiring permission to use accessibility features.

  3. Open System Preferences. Open the Security & Privacy pane. Click the Privacy tab. Click Accessibility. Click "Click the lock to make changes." Enter your password and click Unlock. Click the plus sign. Select Automator and click Open. Repeat, adding Script Editor. Make sure the checkboxes next to Automator and Script Editor are checked in the list.

(Hopefully, you'll only have to do step 3 once... until the next macOS upgrade.)

  1. Go back to Script Editor, and try running your script again. Hopefully, in Preview, the Sketch tool will now be selected.

  2. In Script Editor, save your script as an application somewhere in your home folder.

  3. Find the application you just saved using Finder or Spotlight. Run the application. You will get another error about accessibility access.

  4. Return to System Preferences > Security & Privacy > Privacy.

  5. Click the little plus sign again. Browse to the application you just saved, and add it to the list. Make sure the check box next to it is checked.

  6. Now, run your application from the Finder or Spotlight again. Hopefully you will not get an error this time.

  7. Open Automator. Choose File > New. Choose Service. Under "Service receives selected," choose no input. Click any application and choose Other... Choose Preview.

  8. In the "Actions" search box, type application. Drag Launch Application over to the "Drag actions or files here to build your workflow" panel.

  9. Under Launch Application, choose Other..., then browse to your application.

  10. Save the automator action (Service) with a sensible name, like "Preview Sketch Mode" or something easy to remember that you can type exactly.

  11. Make sure the automator action works.

  12. Launch System Preferences and go to Keyboard. Click Shortcuts. Click App Shortcuts. Click the plus sign. Under Application, choose Preview. Under Menu Title, type the exact name of the service name you saved in step 13 above. Assign a keyboard shortcut to it.

You should now have a keyboard shortcut that enables Sketch mode in Preview.