You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

keyboard shortcut to rename file in apple preview

Hi there,


I am scanning a lot of files and I am using Preview 10.0 (944.5) to rename the scanned files and store them in the right archived location of my hard drive.


To do so, right now, I do click on the filename in the Title bar and get that very convenient little box which allows me to rename and move the file to the appropriate location in a couple of clicks.

User uploaded file

I was wondering if any of you would know of a way to have this box show up with a keyboard shortcut instead of clicking on it? I would rather like it as my hands are already on the keyboard and it would save some time when handling several files in a row.


I do know how to create a keyboard shortcut in the Keyboard section of the System Preferences but, as far as I know, it only works for menu commands that you can get from the Menu bar. I haven't find a way to have this box appear from any menu command. Also, the Rename... command from the File menu is not exactly the same and does not allow you to move the file on the fly.


Thanks

Lance

iMac, OS X Yosemite (10.10)

Posted on Jul 23, 2018 6:21 AM

Reply
Question marked as Top-ranking reply

Posted on Jul 23, 2018 1:36 PM

Let's turn that script into an Automator Service, which a keyboard shortcut can be assigned.


Dock : Launchpad : Other : Automator.

  1. New Document
    1. Service
    2. The Automator interface will appear as three columns:
      1. Select Utilities : Run AppleScript, and drag that action into the larger right-hand workflow window.
      2. Add the AppleScript from above. The finished Service workflow will look like this:
        User uploaded file
        You can right-click on this image and open in a new window for better legibility. Click on the hammer icon to compile it before the next step.
      3. File menu : Save

        I called mine preview_rename. It is saved in ~/Library/Services as preview_rename.workflow.

  2. Quit Automator
  3. System Preferences : Keyboard panel : Shortcuts : Services : preview_rename.
    1. It will be near the bottom in the General category.
    2. Click once on the light-gray None opposite the Service name. It will change to a button that says "Add Shortcut." Click again, and then type control-r on the keyboard. This is your new shortcut.
  4. Quit System Preferences.


Now, when you have a PDF open in Preview, you can type control-r and the Automator Service will fire the AppleScript in it with the same result as when you ran it in the Script Editor. There will be no need to register the Automator Service, though it may require Automator itself to be added to the Privacy : Accessibility window in Security & Privacy.

Similar questions

15 replies
Question marked as Top-ranking reply

Jul 23, 2018 1:36 PM in response to lanceloz

Let's turn that script into an Automator Service, which a keyboard shortcut can be assigned.


Dock : Launchpad : Other : Automator.

  1. New Document
    1. Service
    2. The Automator interface will appear as three columns:
      1. Select Utilities : Run AppleScript, and drag that action into the larger right-hand workflow window.
      2. Add the AppleScript from above. The finished Service workflow will look like this:
        User uploaded file
        You can right-click on this image and open in a new window for better legibility. Click on the hammer icon to compile it before the next step.
      3. File menu : Save

        I called mine preview_rename. It is saved in ~/Library/Services as preview_rename.workflow.

  2. Quit Automator
  3. System Preferences : Keyboard panel : Shortcuts : Services : preview_rename.
    1. It will be near the bottom in the General category.
    2. Click once on the light-gray None opposite the Service name. It will change to a button that says "Add Shortcut." Click again, and then type control-r on the keyboard. This is your new shortcut.
  4. Quit System Preferences.


Now, when you have a PDF open in Preview, you can type control-r and the Automator Service will fire the AppleScript in it with the same result as when you ran it in the Script Editor. There will be no need to register the Automator Service, though it may require Automator itself to be added to the Privacy : Accessibility window in Security & Privacy.

Jul 24, 2018 1:27 PM in response to lanceloz

Copy the following AppleScript into an Automator Service's Run AppleScript action:


try

-- kill the fontd process by exact match on its name

do shell script "pkill -i -x fontd"

delay 1

display dialog "Fontd process is no longer running."

on error

display dialog "Fontd was not running."

end try

return


Service looks like:

User uploaded file

Apparently, an assigned keyboard shortcut (e.g. shift+control+K, control+K) do not work, but you can access the service from the Finder menu : Services panel. I named mine unfontd. You will have to reboot to restart the fontd process.


[Update]. Apparently the Automator Service is not working, though the command syntax when run from the Script Editor does work.

Jul 25, 2018 2:59 AM in response to VikingOSX

Update 2: When I try the specific shortcut cmd-Q, it displays it in the Finder-Services menu (see image) and it works!


User uploaded file


But if I try any other shortcut combination, for instance cmd-E, or shift-cmd-T, or else, it is accepted in the System Preferences - Keyboard - Shortcuts- Services box but is not displayed in the Finder - Services menu to the right of the service, and most importantly does not work!


Strange behaviour...

Jul 25, 2018 6:14 AM in response to VikingOSX

I tweaked your script a little bit to reflect the reality I experience when I do it "manually" from Activity Monitor: that is it sometimes (quite often actually) takes more than a single click on the "Force quit" button before the process is really killed and disappear. Don't know why.


So the following script reflects the manual experience and seems to work now when I keep Activity Monitor open during the test to verify:

User uploaded file


I am looking for the error dialog as a "proof" that the process has been killed, hence the change of the content of the error message. I assume that it is killed most of the time at the second attempt.


When verifying with Activity Monitor open, I can see physically the process disappear before I click the OK button of the error message and before it launches the app. As soon as the app shows up, fontd is back again in Activity Monitor.


Very strange indeed...


Many thanks for your advices on Applescript language. It is nice of you.


Lance

Jul 25, 2018 5:48 AM in response to lanceloz

Ordinarily, I avoid keyboard shortcuts that are used in application menus such as the standard ⌘Q for quitting an application. Glad you got it working.


Although the Automator Service would appear to run correctly with the appropriate dialog box, it did not kill off fontd for me. I tried passing an admin password to sudo with the pkill statement, and again, it appeared to run properly but without the desired result. I also changed the pkill signal sent to fontd from the default TERM (e.g. 15) to KILL (9) without success too. So double-check that fontd is still running afterward.


Apple has an AppleScript Language Guide that is invaluable for understanding its syntax, and in some cases, it also provides examples. Both MacScripter, and Apple StackExchange (aka ⌘AskDifferent) can provide help and examples. Click on the Tags menu on the AskDifferent site, and enter applescript in the Tag window. There is also the AppleScript section of the macosxautomation site with learning and examples.


Keep in mind that Apple has changed AppleScript behavior over the years, so if you try an older 2007 AppleScript example, it may not work in 2018 AppleScript without some tweaking.


Many of the AppleScript books on Amazon were done many years ago. Books by Neuburg, Soghoian, Rosenthaal, and Waldie may still be relevant even years later.

Jul 23, 2018 9:26 AM in response to lanceloz

You can only assign keyboard shortcuts to unassigned application menu items. You would need a GUI AppleScript to press that document title bar button.


tell application "Preview" to activate

tell application "System Events"

tell application process "Preview"

set frontmost to true

tell menu button 1 of front window to perform action "AXPress"

end tell

end tell

This script name would need to be added to System Preferences : Security & Privacy : Privacy : Accessibility items.

Running the script once opens the title bar panel. Running it again will close that panel.

Jul 23, 2018 9:26 AM in response to VikingOSX

Thanks for your help VikingOSX!


I created the script in AppleScript editor and tested it successfully from the editor itself. Nice job.


Two questions though:


1) you tell me to add the script name to System Preferences : Security & Privacy : Privacy : Accessibility items. Can't seem to be possible to me as I can see the script whith its scpt extension but it is greyed out when trying to add it from the Accessibility zone as it seems to expect only applications.


2) and once it will be added, how can i associate the script with a keyboard shortcut? From the System Preferences?


Lance

Jul 24, 2018 10:46 AM in response to VikingOSX

Hi VikingOSX,


I was wondering if an Applescript could help do the following:


1 open activity monitor

2 force quit the fontd process (when I do it manually, I sometimes have to click "Force quit" a few times before it appears to work)

3 quit activity monitor

4 launch a business application


The reason is that business application I am using seems to have a bug now with the current version of OSX and their developers recommend to kill the fontd process first before to launch the application; in order to avoid excessive slowness.


It is just a pain to do so every time and with the way you created the first script, I was wondering if something like this could be done as well.


Sorry for abusing your skills :-)

Jul 24, 2018 11:12 AM in response to VikingOSX

If I could suspend the use of this application, I probably would. But as of now, it would be really difficult to stop using this app as I have been using it to record my financial data for store for over 8 years now. It would mean that I would lose too much history of data.


Right now, in order to use it, I do force quit fontd everytime I start this application. It does not seem to harm OSX. But I could be wrong.


Until they release a new version, I have to do it manually everytime. I am actually trying to automate this.

Jul 25, 2018 2:28 AM in response to VikingOSX

Thanks again, VikingOSX.


I created the service with your script, added the launch application next to it. And I can run it directly from the Finder Services menu.


By the way, it seems that the business application I launch after killing fontd has the fontd process running as soon as it is launched. So it does not requires a reboot to turn it on again. But I agree with you that this is a very inelegant way of processing.


Great job again! Do you know of any website that could provide easy and quality tutorial to get familiar with AppleScript? It looks that I have underestimated the power of this language when combined with automator.

Jul 25, 2018 10:52 AM in response to lanceloz

There are process that automatically re-start should they ever quit. You can tell this by looking in their startup plist [ Some assembly required, since I do not know what plist to look into nor how to read the plist for this information. ]


I found the book the most helpful when learning applescript. I still use this book as a reference. It's in need of a new edition.

Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Third Edition the book


Help to know the terminal,Unix, commands too.




Practical Guide to Linux Commands, Editors, and Shell Programming, A (2nd Edition) [Paperback] the book Don't be fooled by the name, the second addition includes Mac OS X. And it will take you awhile to learn, Unix commands and probably more than one book.


R

keyboard shortcut to rename file in apple preview

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.