AppleScript to Show/Activate PopClip

Hi @nick, I’m running this AppleScript to show/hide popclip menu but it only shows me two options in the menu, while the usual selecting of text shows 4 options (which is right). Can you help on this?

tell application "PopClip"
	appear
end tell

normal selection
image

via script

How are you triggering the AppleScript? If you are triggering it from Script Editor then Script Editor itself will become the active application and PopClip will show options for the current selection in Script Editor. I think that could explain it but if not, post more details and let’s dig into it.

Triggering it via Alfred. What else can I do to make it work normally?

Hmm, I’ll need to think about this. What happens when you use PopClip’s own keybaord shortcut, same result or different?

It works correctly

Thanks. Please tell me more about this Alfred trigger. What workflow/configuration are you using? How exactly in Alfred are you triggering it? Tell me enough that I can set it up exactly the same way myself so I can reproduce the fault.

…but in general you need to make sure that whatever you are triggering it from is not grabbing the focus from the app that you selected the text in. When triggered by AppleScript, PopClip acts on the current focused app.

My flow is a little weird :smile:

I use BetterTouchTool to map all keyboard shortcuts (since it captures every single key like Fn) and keep all scripts/automations in Alfred. PopClip also directs most things into Alfred. I like keeping reusable stuff in one place (Alfred).

In this case, I’m using BTT to trigger an Alfred workflow via external trigger. Strangely, if I trigger the Alfred workflow directly, PopClip shows all the options. If I do BetterTouchTool > Alfred trigger, it only shows 2.

here is the workflow link Dropbox

1 Like

Got it. So, I installed the Alfred workflow, and I set up BTT with a KB shortcut to trigger opening the URL alfred://runtrigger/com.alfredapp.ankitr.popclip/popclipactivate/?argument=test

I get the same results as you.

I fired up PopClip in debug mode and I can see that when the URL to trigger PopClip via Alfred is fired in BTT, Alfred becomes active and claims the input focus. (I’m not sure if Alfred’s code is explicitly claiming the focus, or if this is a limitation of the macOS LaunchServices system that opens URLs. It’s probably the latter.)

Alfred then runs the AppleScript to activate PopClip, which invokes itself against Alfred, because Alfred is now the focused app (even though it has no UI on screen).

So the issue here is Alfred getting the focus when invoked with a URL scheme.

What I suggest (though you may not like it!) is just to put the AppleScript for your KB shortcut directly in BetterTouchTool itself.

1 Like