Hello,
Have any of you come across or written a script that would make it possible to invoke a specific custom Print to PDF menu option?
I have a custom print to pdf option called “ACTION”, which simply puts the pdf in a folder with that name. In order to send a document to it, I type Command + p, click on PDF and then click on ACTION. I would like to be able to accomplish this only using the keyboard, e.g. typing Command + Shift + p or Command + p and then Command + Shift + p.
I have tried Keyboard Shortcuts in Preferences but could not accomplish my goals. Perhaps an Applescript with GUI Scripting could accomplish this? The script below, in conjunction with FastScripts or a similar application, accomplishes something along the same lines: it allows one to have Mail Load Images using a keystroke shortcut.
Any thoughts?
Thank you,
Erik
(*
Click the Load Images button in an open Mail message.
This is to work around Mail's idiotic inability to Load Images via keyboard shortcut.
Attach this to a keystroke using FastScripts, Keyboard Maestro, or some other utility.
Written May 2013 by Michael A. Alderete
Project URL: http://aldoblog.com/link/load-images-applescript
Version History
1.0 -- Initial release, 2013-05-06
1.0.1 -- Consolidate reference to button to a single line, instead of two separate references (never released)
1.1 -- Add OS version detection, use right reference for Mail.app version (never released)
1.2 -- Refactor the OS detection and button reference (never released)
1.3 -- Use a cascade of statements to get various Mail version/config permutations, release 2013-05-27
Use as you please, give credit if you like.
*)
-- You can comment this out after you run it once, for slightly faster performance.
-- It just makes sure you really have GUI Scripting enabled.
GUIScripting_status()
tell application "System Events"
tell process "Mail"
try
-- Verify there is a window where it's possible to load images
-- From <https://discussions.apple.com/message/11234439#11234439>
if not (window 1 exists) then return beep 1
set loadImagesButton to my getLoadImagesButtonReference()
-- Make sure there's a [Load Images] button in the window
if not (loadImagesButton exists) then return beep 1
-- Actually click the button
click loadImagesButton
end try
end tell
end tell
-- Check to see if assistive devices is enabled
-- From <http://www.macosxautomation.com/applescript/uiscripting/>
on GUIScripting_status()
tell application "System Events"
set UI_enabled to UI elements enabled
end tell
if UI_enabled is false then
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.universalaccess"
display dialog "This script uses the Graphic User Interface Scripting architecture of Mac OS X, which is currently disabled." & return & return & "Enable GUI Scripting by checking \"Enable access for assistive devices\" in the Accessibility preference pane." with icon 1 buttons {"OK"} default button 1
end tell
end if
end GUIScripting_status
-- Get a reference to the [Load Images] button
-- The UI specifier path to the button changes depending on which version of Mail.app is running,
-- whether the message open in a preview pane or independent message window, and
-- whether you have the "classic" layout enabled (luddites unite!), or use the new sideways layout (like an animal).
on getLoadImagesButtonReference()
tell application "System Events"
tell process "Mail"
if (my isBeforeLionMail()) then
try
-- Older versions of Mail.app use a simpler UI specifier
-- From: https://discussions.apple.com/thread/2405934
set loadImagesButtonRef to a reference to button "Load Images" of front window
end try
else if (my isLionMail()) then
-- Cascade through a series of attempts to get the button reference
try
-- The [Load Images] button in an independent message window
-- Found with [UI Browser](http://pfiddlesoft.com/uibrowser/).
-- Also described here, but with a different scripting intent:
-- http://superuser.com/questions/421215/mail-app-showing-remote-images-automatically-for-specific-senders
set loadImagesButtonRef to a reference to button ¬
"Load Images" of UI element 1 of row 1 of table 1 of scroll area 1 of front window
end try
if not (loadImagesButtonRef exists) then
try
-- The [Load Images] button in a mailbox preview pane when in "classic layout"
-- Found with [UI Browser](http://pfiddlesoft.com/uibrowser/).
set loadImagesButtonRef to a reference to button ¬
"Load Images" of UI element 1 of row 1 of table 1 of scroll area 2 of splitter group 2 of splitter group 1 of front window
end try
end if
if not (loadImagesButtonRef exists) then
try
-- The [Load Images] button in a message displayed in a mailbox preview pane when in new (non-"classic") layout
-- [Suggested by John Waers](http://aldoblog.com/2013/05/load-images-applescript-for-apple-mail/#comment-26329)
-- and [David Horne](http://aldoblog.com/2013/05/load-images-applescript-for-apple-mail/#comment-26335)
set loadImagesButtonRef to a reference to button ¬
"Load Images" of UI element 1 of row 1 of table 1 of scroll area 1 of splitter group 2 of splitter group 1 of front window
end try
end if
else
-- Unsupported version of Mail.app
return beep 1
end if
return loadImagesButtonRef
end tell
end tell
end getLoadImagesButtonReference
-- Mac OS X version detection functions
-- We're not going to attempt to support anything before Tiger (10.4), impossible to test
-- For now, don't worry about next version of Mac OS X (10.9)
on isBeforeLionMail()
-- From: http://stackoverflow.com/questions/498323/find-mac-osx-version-installed-using-applescript
set osVersion to system version of (system info)
if ((osVersion begins with "10.4") or (osVersion begins with "10.5") or (osVersion begins with "10.6")) then
return true
end if
return false
end isBeforeLionMail
-- Lion (10.7) changed the UI specifier for the [Load Images] button
on isLionMail()
set osVersion to system version of (system info)
if ((osVersion begins with "10.7") or (osVersion begins with "10.8")) then
return true
end if
return false
end isLionMail