MacOS – Keyboard shortcut for a service stopped working

applescriptkeyboardmacos

I have made a custom keyboard shortcut for Finder that runs a script that copies the full file path to the clipboard. The shortcut is Control + Alt + Command + C.

It has always worked, but today it suddenly stopped working. I tried sniffing for any program that activates when the shortcut is pressed using /usr/bin/sudo opensnoop in Terminal but to no success. I have not recently installed any new programs and I can't recall anything particular happening that could be the culprit.

How do I get my shortcut back?

My Automator workflow looks like this (the actions are in Swedish):
enter image description here

Best Answer

This is an extended comment containing some suggestions of things to try and help you diagnose your problem, but I don't claim that any of these will definitely solve your issue:

Check defaults to look for clashing keyboard shortcuts

Your service runs with a different shortcut and inside Automator. So there is possibly a conflicting shortcut that has appeared and is blocking your original.

In Terminal (or other terminal emulator), you can retrieve all the active app-specific keyboard shortcuts:

defaults find NSUserKeyEquivalents

and your service workflow shortcuts:

defaults find NSServicesStatus 

The symbols used to represent modifier keys are:

  • @: command
  • $: shift
  • ~: alt/option
  • ^: ctrl

Thus, +++C is symbolised as @~^c (the c is lowercase).

You can do a general defaults search through all the preference files to look for that specific combination of characters:

defaults find '@~^c'

You can also search for matching preferences files:

grep -iE '@~\^c' ~/Library/Preferences/* /Library/Preferences/* 2>/dev/null

which, upon matching, will output something like:

Binary file /Users/CK/Library/Preferences/com.apple.ServicesMenu.Services.plist matches

and then you can target the specific domain to examine its defaults:

defaults read com.apple.ServicesMenu.Services

Third-party Application

There are third-party apps that allow you to see what keyboard shortcuts are being used by which applications on your system. The one I know of is KeyCue:

I'm not endorsing the product and have never used it myself, but I believe it would be very useful in finding out if there's interference from another application or from within Finder stopping you from using that shortcut combination.

It's a paid app (€19.99), but has a free evaluation period:

All our products are available for evaluation before purchase. As long as you do not have a license key, KeyCue operates in trial mode and occasionally displays a registration reminder instead of the shortcut table.


ADDENDUM : Your Workflow

Thanks for posting a screenshot of your workflow. There doesn't appear to be anything obstructive about it that would obviously cause it to stop responding to a shortcut.

However, I'm going to take the opportunity to suggest some edits to it, as I can see what your AppleScript is doing, but it's not doing it in the most optimal way.

Here is your current workflow:

The OP's current workflow

It starts by taking the files/folders passed to the service/quick action and copying them to the clipboard. There's no need to and it only makes Automator do more work than it has to. Instead, you can delete that first action, and have the files/folders pass directly into the AppleScript, where they will be stored in the variable input.

The AppleScript itself makes use of application "BBEdit" unnecessarily, so I suggest removing that and I'll show you how to make the changes you need without calling out to it.

If I'm interpreting your goal correctly from what you said and from what I see in your workflow, you wish to select some files or folders, press your shortcut key combination, and have file URL references to those files/folders copied to the clipboard, e.g. file:///Users/CK/Desktop/somefile.txt.

Your method works ok in some situations, but will produce incorrect results in a few other situations:

  • Any file/folder with a space in its name will not return a correct and clickable file URL link. For example, the file with path /Users/CK/Shared Items/myfile.ext will be copied to the clipboard as file:///Users/CK/Shared Items/myfile.ext, which is an incorrectly encoded URL string, thus the hyperlink will appear like this: file:///Users/CK/SharedItems/myfile.ext. (Technically, other character entities need to be percent encoded to form a valid URL, but I think they're less important if you're just looking to use them locally in Finder.)

  • Your present method replaces occurrences of "/Volumes" and occurrences of "/Users" with "file:///Volumes" and "file:///Users", respectively. This will cause problems for any file path that might look something like this:

    /Users/CK/Backup/Preferences/Volumesettings/Volumes.dat
    

    There are three replacements waiting to happen there, which would yield:

    file:///Users/CK/Backup/Preferencesfile:///Volumesettingsfile:///Volumes.dat
    

Having cleaned up the script, and deleted the superfluous action, here is what I am suggesting would be a smarter way to implement your service/quick action:

Suggested edit to workflow

The AppleScript:

property text item delimiters : linefeed


on run {FSItems}
    local FSItems

    tell application "System Events" to repeat with FSItem in FSItems
        set FSItem's contents to the URL of FSItem
    end repeat

    set the clipboard to FSItems as text
end run

It utilises System Events (which is a faceless, background application that can perform efficient file system operations) to take each file/folder passed into the workflow and obtain an AppleScript property named URL, which conveniently holds the perfectly-formatted, validated file URL reference for a file. Once it has a list of file URLs, it combines them into a single piece of text—one file URL per line—and places that on the clipboard.

Thus, selecting the following files/folder in Finder (if you imagine I selected three files and a folder, then pressed the hotkey to trigger the service):

/Users/CK/Desktop/NSImage.png
/Users/CK/Desktop/GIF Images
/Volumes/Lepton 1.5.2-alpha-2
/Users/CK/Desktop/mandelbrot.js

would yield the following clipboard contents (this is a live test):

file:///Users/CK/Desktop/NSImage.png
file:///Users/CK/Desktop/GIF%20Images/
file:///Volumes/Lepton%201.5.2-alpha-2/
file:///Users/CK/Desktop/mandelbrot.js