Jump to content

applescript "tell application" without losing focus from Alfred


Recommended Posts

Hey gang,

 

I had in mind to create a very simple and straightforward Fantastical workflow. A few were already made but they don't do what I would like them to do:

I want to type something in alfred and have it being typed in fantastical at the same time (the focus stays on alfred at all times), and then only switch to fantastical when i press enter.

 

You could imagine the same use case for the "Help" search box from every app, or from "Shortcat"...

 

 

The applescript for Fantastical is rather simple:

tell application "Fantastical" to parse sentence "{query}"

Is there a way to trigger that applescript without Alfred losing focus ?

 

 

I have also tried a simpler thing:

tell application "AppleScript Editor" to quit

And Alfred will lose focus if "AppleScript Editor" is the frontmost app but not if it isn't.

Link to comment

Interesting idea.

It seems like it might be possible to an (limited) extent, yes. Not in this case, perhaps, but why do you want Alfred open in this case anyway? If you have a script filter with

tell application "Fantastical" to parse sentence ""

as soon as you start typing, it’ll open fantastical and seamlessly transition, letting you continue writing on Fantastical’s box.

 

Following your request, though, I’ve also tried (using fc as the way to call the Script Filter)

query_save="/tmp/fantastical"

if [[ "$(cat ${query_save})" != "{query}" ]]; then
  echo "{query}" > "${query_save}"
  osascript -e 'tell application "Fantastical" to parse sentence "{query}"'
  osascript -e 'tell application "Alfred 2" to search "fc {query}"'
fi

The reason it needs that save file and the if check is that without it, we’re left in an infinite loop calling Alfred.

 

This should work, in theory, and to an extent it does, leaving Alfred open. The issue seems to be Fantastical grabbing focus. When we have the line to call Alfred, it should steal focus again, and yet it doesn’t (it isn’t a timing issue, as adding a delay will lead to the same result), neither does telling it to activate, which makes it seem like Fantastical is the one blocking this possibility.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...