Skip to content

Instantly share code, notes, and snippets.

@jerrykrinock
Last active September 7, 2020 03:37
Show Gist options
  • Save jerrykrinock/10bf33a980067750c956 to your computer and use it in GitHub Desktop.
Save jerrykrinock/10bf33a980067750c956 to your computer and use it in GitHub Desktop.
Saves the current Finale music score as a PDF file, named and located, overwriting old PDF, with one keystroke
-- Version: Substantially rewrote on 2020 09 06 to use Graphics > Export Pages instead of
File > Print > Save as PDF. Also now works with Finale 26 and macOS 10.11 Big Sur (Beta 6).
Have not tested with earlier versions.
--------------------------------------------------
-- Begin Parameters which you should edit
--------------------------------------------------
-- Set saveDirPath to the path to the directory you always save your PDF outputs saved to.
-- Possibly starting with OS X 10.10.2, the "~" in the following no longer expands to your home folder. Path must start with /Users/<yourShortName>
property saveDirPath : "~/Documents/Music-Perf/Notation+MIDI/Titles(Notation)/"
-- Set this to whatever version/year of Finale you're using
property finaleAppName : "Finale" -- name of application package
property finaleBundleID : "com.makemusic.Finale26"
-- If you want Finale to automatically save the document, to un-dirty it, after printing to pdf, set the following to "true". (Annoyingly, Finale 2012 dirties a document after "printing" to a pdf.)
property saveAfterPdf : true
-- If you always want to overwrite a previous PDF of the same name without asking, set the following to true
set dontAskJustustOverwrite to true
-- Since we are using GUI scripting, we need names of menus and menu items, which depend on the localization of Finale. Finale 26 has two localizations. Enter "en" if you are using the English localization of Finale, "es" for Spanish.
set finaleLocalization to "es"
--------------------------------------------------
-- End of Parameters which you should edit
--------------------------------------------------
property leftArrow : ASCII character 28
property rightArrow : ASCII character 29
property upArrow : ASCII character 30
property downArrow : ASCII character 31
property deleteKey : ASCII character 8
-- Remind the user that this script uses GUI scripting, and that touching the mouse or keyboard while the script is running will probably cause unexpected results.
say "Don't touch!"
-- The following is not needed for normal operation, but is needed when debugging this script and running from Script Editor.
tell application id finaleBundleID to activate
if finaleLocalization is "en" then
set toolsMenuTitle to "Tools"
set graphicsMenuAndMenuItemTitle to "Graphics"
set exportMenuItem to "Export Pages…"
set saveWindowTitle to "Save file PDF"
else if finaleLocalization is "es" then
set toolsMenuTitle to "Herramientas"
set graphicsMenuAndMenuItemTitle to "Gráficos"
set exportMenuItemTitle to "Exportar páginas…"
set saveWindowTitle to "Guardar archivo PDF"
end if
(* For some reason, the following delay 5 only delays 1-2 when this script is invoked with a QuicKeys keyboard shortcut from within Finale. I wonder if all of the other delays in this script are similarly affected?
say "Will delay"
tell me to delay 5
say "Did delay"
*)
tell application "System Events"
delay 0.7
tell process finaleAppName
click menu item graphicsMenuAndMenuItemTitle of menu toolsMenuTitle of menu bar 1
click menu item exportMenuItemTitle of menu graphicsMenuAndMenuItemTitle of menu bar 1
set the clipboard to saveDirPath
delay 0.5
keystroke return -- Hits the default button, "Aceptar"
delay 1
keystroke "g" using {shift down, command down}
delay 3
keystroke "v" using {command down}
-- Increased the following two delays because one of them was not long enough and "folder was not found" at this point.
-- Click the "Go" button
delay 4
say ("will go")
keystroke return
say ("did go")
-- Click the "Save" button
say ("will save")
keystroke return
say ("did save")
delay 1
-- If this pdf file already exists, OS X will present a "Do you want to replace…" sheet. If the pdf does not already exist, that sheet will not show and the following will cause a couple of alerts to sound.
if dontAskJustustOverwrite is true then
repeat with aWindow in windows
set aTitle to title of aWindow
if aTitle is saveWindowTitle then
set hasSheet to (exists sheet of aWindow)
say "will overwrite"
if hasSheet is true then
log ("Doing overwrite")
delay 0.2
log ("tab")
keystroke tab
delay 0.2
log ("space")
keystroke space
exit repeat
end if
end if
end repeat
end if
if saveAfterPdf is true then
tell me to delay 1 -- If you don't "tell me", it doesn't delay when invoked by QuicKeys. Weird.
keystroke "s" using {command down}
tell me to delay 1 -- If you don't "tell me", it doesn't delay when invoked by QuicKeys. Weird.
end if
end tell
end tell
return
say "Done"
PROBLEM
When using MakeMusic's "Finale" music notation software on my Macintosh, I hardly ever print to
paper but often want to export my document as a PDF file, and always into the same directory where
I keep all of my products. This takes about a half dozen keystrokes, plus navigating into my
products folder, and I often make a mistake and need to re-do it.
TO MAKE IT LESS PAINFUL, USE THIS SCRIPT
This AppleScript automates the action. After I put in all the delays to make it reliable on my
2019 MacBook Air, it takes about 20 seconds to run, not too much faster than I could do manually
*if* I don’t make any mistakes. But I find it much more enjoyable to rest my brain and watch the
machine do the work.
TO INSTALL THIS SCRIPT
• Edit the parameters at the top to suit your needs
• Install it somewhere easily accessible from within Finale. For example, you could save it as
an Application (.app) in your /Applications folder, then access it using the macOS built-in
Spotlight tool, or your application laucher of choice.
TO RUN THIS SCRIPT
• Activate a document window in Finale that you wish to print to PDF.
• Run the script, using the keyboard shortcut or whatever..
• Because this script is a GUI Script, after triggering it, you need to keep your hands off
of the keyboard and mouse for 10 seconds or so, while it does its thing. Otherwise,
it could do something else instead. Wait until it says "Done".
TROUBLESHOOTING
Finale has basic AppleScript support (open, save, print, etc.) but not what we
need to do this, so I resorted to GUI scripting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment