I have a workflow in automator that "receives a selected PDF file in Finder", then "Open finder items", follow by "Set PDF Metadata"
When running the workflow, "Set PDF Metadata" opens a window that takes some inputs (title, author, and so on), and then requires me to press "Continue" to move on the next step of the workflow.
The window that "Set PDF Metadata" opens is always partially minimized, so I have to manually resize it bigger every time I run the workflow. Is there some way I can specify the size and position that the window should open at?
To replicate this behavior a simple workflow that goes as follows should work:
- Get specified finder item, and specify a PDF file
- Open finder items (open with default application)
- Set PDF metadata, with the "Title" and "Author" boxes checked
Further information and screenshots:
Default PDF application is Preview
OS is MacOS Sierra 10.13.3
Best Answer
Yes, it is possible to set the position and size of the Set PDF Metadata action's window when run from an Automator Service, however it requires a bit of a creative workaround.
I have tested the following and it works for me under macOS High Sierra.
There are two primary components for this process, one being the Automator Service named Edit PDF Metadata, and the other, an AppleScript application that sets the
position
andsize
of the Set PDF Metadata action'swindow
.For the Automator Service, which I saved as Edit PDF Metadata, the image below shows the settings.
Example code for the Run Shell Script action:
open
command could be shortened toopen -a "Resize Set PDF Metadata Window"
. Then it doesn't matter where the Resize Set PDF Metadata Window.app is saved, it's found automatically. I've include the fully qualified pathname just so there was no ambiguity.Next, the desired position and size of the window for the Set PDF Metadata action needs to be determined:
In Script Editor, open a new document with the following AppleScript code, but do not run it yet, just have it ready.
Now in Finder, select a PDF document and right-click selecting Edit PDF Metadata from the Services section of the context menu.
Then position and resize the Set PDF Metadata action's window on the screen as wanted, leaving it on screen for the time being, then back in Script Editor, run the code you prepped to get the desired
position
andsize
of thewindow
for the Set PDF Metadata action.On my system it returned, e.g.:
{{870, 280}, {700, 290}}
, on my 27" Thunderbolt Display.Make note of the
results
for use with the code, which is used next, to create the Resize Set PDF Metadata Window.app in Script Editor.You can now click the Cancel button on the Set PDF Metadata action's window, as it has served its purpose to this point.
Now create the Resize Set PDF Metadata Window.app in Script Editor using the following example AppleScript code:
Change the value of
set position to
andset size to
as appropriate and save as an application named Resize Set PDF Metadata Window in the/Applications
folder.Note that on my system
30
, inif i > 30 then return
, equates to~5
seconds and is used sorepeat until
is not an endless loop, if something happens andwindow 1 of process "com.apple.automator.runner"
doesn't appear for some reason.Before really using the new Automator Service for the first time, you need to add Resize Set PDF Metadata Window.app to: System Preferences > Security & Privacy > Privacy > Accessibility
With that done, Edit PDF Metadata is ready to used on a PDF document in Finder from the Services section of the context menu. It is also available from the Finder > Services menu as well. Also a keyboard shortcut can be assigned to the service in: System Preferences > Keyboard > Shortcuts > Services > Files and Folders
Also note that by default, the metadata added to the selected PDF document is automatically saved upon pressing the Continue button, so there is no need to use the Quit Application action set to Preview with the [√] Ask to save changes check box clicked. That is unless you added the Open Finder Items action, then add back the Quit Application action set to Preview too. (Note that Ask to save changes did not work in my testing.)
NOTE: Use caution with the Rename PDF Documents action, because if the Title check box is checked in the Set PDF Metadata action's window but text box is left blank, it will delete the PDF document upon clicking the Continue button! (This appears to be a bug in this action under macOS High Sierra.) Additionally, if you set the Title to the name of an existing PDF document, while the metadata is changed, nonetheless the target file is not renamed. As always, insure you have proper backups before running automated services upon your files.
The only drawback to this method that I can think of, is that only one Automator Service can be run at a time, this one, otherwise it will not be able to get window 1 of process "com.apple.automator.runner" if there is more than one "com.apple.automator.runner" process running. But how often does one really need to have more then one Automator Service run at a time.
If you do not want to have the Dock Tile for the Resize Set PDF Metadata Window.app show on the Dock, then in Terminal use the following command:
Afterwards, you can use the command with
-bool no
to have to have the app's Dock Tile show on the Dock.Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.