Jump to content

Alfred stealing focus back after applescript


Recommended Posts

Hi

 

I use fluidApp( http://fluidapp.com/ ) for a whole bunch of websites and like to pin then to the task menu so they are still running but are out of sight.

 

I have been trying to find a way to get Alfred to force them to activate but have been running into trouble with Alfred setting the focus back to the previously running app.

 

The closest i have gotten is a workflow that Opens the app and then had a output script to send a hotkey to the system that brings the window to the front. 

 

This causes the app to pop up for a second or two before focus returns to the previous window causing the fluidapp to close.

 

Is there a flag i can set on a workflow to disable to focus setting behaviour?

 

Thank you

 

 

 

the sample applescript i'm using: 

 

on is_running(appName)
	tell application "System Events" to (name of processes) contains appName
end is_running

on activate_app()
	tell application "System Events"
		keystroke "m" using {command down, shift down, option down, control down}
	end tell
end activate_app

if is_running("APPNAME") then
	activate_app()
	return "Running"
else
	tell application "APP" to activate
	delay (1)
	activate_app()
end if
Edited by phcyso
Link to comment

I'd use bash.  The built-in open command has a flag -g which opens an app without bringing it to the foreground.

 

If you want to wrap it in Applescript, it'd look like this:

 

do shell script "open -g /Applications/XXX.app"

Link to comment

I'd use bash.  The built-in open command has a flag -g which opens an app without bringing it to the foreground.

 

If you want to wrap it in Applescript, it'd look like this:

 

do shell script "open -g /Applications/XXX.app"

The app already opens in the background by itself , I am trying to force it to show its window though its keyboard shortcut.

 

 

@phcyso: Your script works perfectly for me. How are you triggering the script?

I have been trying to use the workflow action 'run script' and run 'nsAppleScript'

They work in that the window flashes up but as the app has no dock icon and is just a floating window the focus reverts to the previous window.

 

The script works perfectly if i trigger it from the terminal manually. It does not work if i use the 'terminal command' action to run the script.

Link to comment

Sorry, I wasn't clear. It doesn't matter how you run the script. How are you triggering the workflow? Keyword? Hot Key?

Ah, sorry

 

I'm triggering it by Keyword.

 

i just tried it by hotkey as well, exactly the same thing, flashes up for a moment then disappears again.

Link to comment

Well i have no idea what the difference is but i tried it in debug mode and it worked, 

Then i tried it not in debug mode and it worked. 

 

i haven't changed anything in the script or workflow

 

Thank you all for your help, when i was trying before it must have been some program interfering with it.  :angry:

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...