1

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:

  1. Get specified finder item, and specify a PDF file
  2. Open finder items (open with default application)
  3. 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

  • 1
    I don’t get a window. After checking the relevant boxes and entering information into the fields, the PDF metadata just gets set, without a separate window manifesting. You’re going to need to be more specific about how this comes about for you: MacOS version, your default PDF program, a screenshot or two. – CJK Mar 3 '18 at 0:04
  • @CJK, If when the Automator Service runs, the Set PDF Metadata action's dialog shows, then in the Options of the Set PDF Metadata action, the Show this action when the workflow runs check box is checked. – user3439894 Mar 3 '18 at 2:02
2

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 and size of the Set PDF Metadata action's window.

For the Automator Service, which I saved as Edit PDF Metadata, the image below shows the settings.

  • Note that the PDF document does not first have to be opened to set the metadata and why there is no Open Finder Items action. If you were doing it the see information in the document as a reference to be used in the Set PDF Metadata action, you can add it back in.

Example code for the Run Shell Script action:

open -a "/Applications/Resize Set PDF Metadata Window.app"
echo "$1"
  • Note that the fully qualified pathname to the app does not necessarily need to be used and the open command could be shortened to open -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.

Automator Service

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.

tell application "System Events" to ¬
    get {position, size} of window 1 ¬
        of process "com.apple.automator.runner"

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 and size of the window 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:

tell application "System Events"
    set i to 0
    repeat until (exists window 1 of process "com.apple.automator.runner")
        delay 0.1
        set i to i + 1
        if i > 30 then return
    end repeat
    tell window 1 of process "com.apple.automator.runner"
        set position to {870, 280}
        set size to {700, 290}
    end tell
end tell
  • Change the value of set position to and set 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, in if i > 30 then return, equates to ~5 seconds and is used so repeat until is not an endless loop, if something happens and window 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:

defaults write '/Applications/Resize Set PDF Metadata Window.app/Contents/Info.plist' LSUIElement -bool yes

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.

  • 1
    What a great answer. Such excellent detail. – CJK Mar 4 '18 at 1:52
  • Thank you very much for the great answer. I have two questions though: 1) Since we are running the script to resize the window before the dialogue window is actually opened, does this mean that theres some background process(com.apple.automator.runner?) that dictates the position and size of open dialogue windows? 2) What is the purpose of the echo "$1"$ after the open command? The AppleScript looks like it does everything, so is this echo just executing the script (perhaps since we are passing inputs as arguments?) – majmun Mar 4 '18 at 3:01
  • 1
    @majmun, The process com.apple.automator.runner is the process that's running the Automator service workflow and exists before any actions are processed. window 1 of process "com.apple.automator.runner" is the window that appears when the Set PDF Metadata action is triggered. By using the open command with the Resize Set PDF Metadata Window.app in the the Run Shell Script action, this enables the ability to resize the window when it does appear, which is also why it has to run first and loop until the window does appear. Continued in next comment... – user3439894 Mar 4 '18 at 3:48
  • 1
    @majmun, Without the functionality provided by the open command, the prompt immediately returning allowing further code to be processed independent of what open executed, and the code used in the Resize Set PDF Metadata Window.app, there is no other way I know of or can think of off the top of my head that will do as you have asked. The echo "$1" is absolutely necessary to pass the input argument, the fully qualified pathname of the PDF document selected in Finder, in the case, to the Set PDF Metadata action. Continued in next comment... – user3439894 Mar 4 '18 at 3:48
  • 1
    @majmun, One thing I left out of the Run Shell Script action, because it wasn't needed on my system, was a delay between the open command and the echo command, e.g. sleep 1, to insure the AppleScript app was fully running before the Set PDF Metadata action is triggered. On a slower system this could be necessary, but obviously it's working for you without and I'm mentioning it more so if it's needed for someone else using this type of workaround. – user3439894 Mar 4 '18 at 3:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .