LeEnno/alfred-terminalfinder

fi cannot bring hotkey window to front

Closed this issue · 7 comments

iterm2 3.1 beta 5
macOS 10.12.6
current workflow version

There is always a hotkey window in the background. When I use fi, however, it open a new tab in hotkey window profile but not bring hotkey window to front. I trie append tell application "System Events" to key code 103(which F3 is my hotkey) but it doesn't work.

Sorry for getting back to you that late, apparently this one slipped through my mailbox.

Have you found a solution to your problem?

I don't work with hotkey windows and I don't know if there is a way to speak to them via AppleScript.

I tried to find a way but failed. Currently I use oh-my-zsh osx plugin to Implement similar functions.
Will leave this open for ideas.

I asked this to the author of iTerm and his suggestion is to do some of the work in the python scripting API. https://gitlab.com/gnachman/iterm2/issues/8303

One way I thought about solving this is that after we get the path from the frontmost app, we can move to iTerm's scripting API to process that path. That should make the workflow work with all kinds of windows. It should even be possible to open it in a new window or pane in tmux, which I think is not currently supported.

Gotta love George ❤️

I have no clue of python but I'm open to pull requests 😊
The only thing I would like to see is no slowdown for the rest of us who don't use hotkey windows.

LeEnno commented

Closing this due lack of activity.

As George points out in the Gitlab issue I mentioned earlier if you have a floating window, it's not exposed to AppleScript and the AppleScript commands for windows won't work. However passing a path parameter to iTerm with the open terminal command opens the path in a new tab, or if there is no window open, it opens it in a new window. It is also snappier than trying to open windows with AppleScript, and since it opens a fresh tab/window by default, the clear; command isn't needed as well. So it essentially boils down to

on alfred_script(q)
	tell application "Finder"
		set pathList to (quoted form of POSIX path of (folder of the front window as alias))
	end tell

	do shell script "open -a iTerm.app " & pathList
end alfred_script

However, the Run NSAppleScript action has a warning message on the top of the window
image

So I changed it to be a Run Script action with the following

tell application "Finder"
	set pathList to (quoted form of POSIX path of (folder of the front window as alias))
end tell

do shell script "open -a iTerm.app " & pathList

image

and it works like a charm for a floating hotkey window this way. 🎉

LeEnno commented

@akaralar thanks for your comment. This solution is now used in the workflow.