alfred-terminalfinder icon indicating copy to clipboard operation
alfred-terminalfinder copied to clipboard

fi in iterm2 doesn't work

Open dustookk opened this issue 8 years ago • 25 comments

iTerm2 Build 3.0.5 Alfred 3.0.3

fi

[2016-07-20 12:19:58][ERROR: action.applescript] { NSAppleScriptErrorBriefMessage = "Expected end of line but found class name."; NSAppleScriptErrorMessage = "Expected end of line but found class name."; NSAppleScriptErrorNumber = "-2741"; NSAppleScriptErrorRange = "NSRange: {566, 6}"; }

dustookk avatar Jul 20 '16 04:07 dustookk

Thanks for reporting.

  1. Are you using the current workflow version?
  2. If so, when did it stop working?

LeEnno avatar Jul 26 '16 17:07 LeEnno

  1. yes.
  2. when I press fi, nothing shows up : )

dustookk avatar Jul 27 '16 09:07 dustookk

So you just installed it and it never worked at all?

LeEnno avatar Jul 27 '16 09:07 LeEnno

It only work with the default terminal. - -|||

dustookk avatar Jul 29 '16 15:07 dustookk

Have you used TerminalFinder before and did it work for you? Or has it never worked for you?

LeEnno avatar Aug 05 '16 08:08 LeEnno

Hi, I have the same problem and I find the same error messge in console. I haven't used TerminalFinder before. It only work with the default terminal.

mondongxr avatar Aug 06 '16 02:08 mondongxr

Thanks @mondongxr.

Does running the following script in the script editor work?

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

tell application "System Events"
  -- some versions might identify as "iTerm2" instead of "iTerm"
  set isRunning to (exists (processes where name is "iTerm")) or (exists (processes where name is "iTerm2"))
end tell

tell application "iTerm"
  activate
  set hasNoWindows to ((count of windows) is 0)
  if isRunning and hasNoWindows then
    create window with default profile
  end if
  select first window

  tell the first window
    if isRunning and hasNoWindows is false then
      create tab with default profile
    end if
    tell current session to write text command
  end tell
end tell

LeEnno avatar Aug 08 '16 19:08 LeEnno

Thank you. I copy your script into Script Editor and run it, but there is the same error.

mondongxr avatar Aug 09 '16 08:08 mondongxr

Thanks for you support. Can you drill down where exactly (=at which line) the error occurs? I can't reproduce it, so it's a little hard for me.

LeEnno avatar Aug 09 '16 09:08 LeEnno

Today I find the script works! But I don't know how it works suddenly. I copy the script into Script Debug and run it. At the first time, it's not ok. In the editor the word 'window' in this line "create window with default profile" is highlighted. But when I choose debuging and run again. There is on error again and my iTerm opened normally. Interestingly, the error isn't appeared again however I run the script. Thank you very much!

mondongxr avatar Aug 10 '16 04:08 mondongxr

Thanks again. I was afraid that it's this kind of nasty one time error. I have to see if I can drill it down. Right now I don't know how to reproduce, let alone how to fix this.

Will leave this open for ideas and further reports.

LeEnno avatar Aug 10 '16 06:08 LeEnno

Afraid I have to confirm that this is also happening for me :(

Both the released script and the version you pasted above fail on my end

Steps to reproduce:

  1. Open Alfred Preferences > Workflows > TerminalFinder > fi
  2. Toggle debugging mode and select "Log All Information"
  3. Launch Alfred > type fi
[2016-08-29 20:03:57][input.keyword] Processing output of 'action.applescript' with arg ''
[2016-08-29 20:03:57][ERROR: action.applescript] {
    NSAppleScriptErrorBriefMessage = "Expected end of line but found class name.";
    NSAppleScriptErrorMessage = "Expected end of line but found class name.";
    NSAppleScriptErrorNumber = "-2741";
    NSAppleScriptErrorRange = "NSRange: {513, 6}";
}

oliverturner avatar Aug 29 '16 19:08 oliverturner

Thx for your report, @oliverturner. I guess you're also a first time user of this workflow and have not used previous versions?

LeEnno avatar Aug 29 '16 19:08 LeEnno

I was having the same problem with Alfred 2 and iTerm 2 (build 3.0.7). Fixed it by copying from the raw source for the fi script: https://raw.githubusercontent.com/LeEnno/alfred-terminalfinder/master/src/fi.scpt.txt Then editing the script in Alfred Workflows, deleting the contents and pasting over the top. Hope this helps.

huntit avatar Sep 03 '16 13:09 huntit

Just checked it, the file in the repo and the script in the workflow diverge by whitespace only. The actual contents are the same.

It may have fixed it for you. Others fixed it by waiting or trying a few times and suddenly it works. So the error is still unknown for now.

Would appreciate any help since I can't reproduce it. Once it works, it seems to always work. I also reinstalled the workflow and still everything works fine.

LeEnno avatar Sep 03 '16 15:09 LeEnno

I've added the problems all of you mentioned to the readme, maybe this will help narrowing down that sucker of a bug.

LeEnno avatar Sep 17 '16 16:09 LeEnno

I also met the issue above ,and hunit's suggestion made no sense.My macOS version is 10.12.1,alfred and iTerm2 are update to latest.

BaoyangBob avatar Nov 04 '16 15:11 BaoyangBob

On my Mac, the "fi" workflow information is stored in an info.plist folder in this directory: ~/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.B52348ED-03A8-4521-9D6F-C9E47246E1EC

Here's the settings that are working for me (macOS 10.12.1, Alfred 2 and iTerm 2 (build 3.0.7):

In the info.plist, under objects -> Item 6 -> config ... argumenttype Number 2 keyword String fi subtext String Open current Finder directory in iTerm text String Finder → iTerm withspace Boolean NO type String alfred.workflow.input.keyword uid String AA3CDA14-C3B5-442B-B117-D61A244C6625 version Number 0

It might be worth checking file permissions, time/date on this file, and the above settings ? Manually copying and pasting in the workflow script (as in a previous suggestion), "touched" the date/time of this file, but I can't see why else it suddenly started working for me.

Hope this helps.

huntit avatar Nov 04 '16 16:11 huntit

hello, when i run #if command, show error: The application /System/Library/CoreServices/Finder.app cannot be opened because its executable is missing.

g63336180 avatar Nov 07 '16 07:11 g63336180

@huntit thx for the hint. I will have a look.

@g63336180 would you mind opening a separate issue to keep concerns separated?

LeEnno avatar Nov 07 '16 10:11 LeEnno

This is working what's working for me:

pi:

tell application "Path Finder"
	set pathList to POSIX path of the target of the front finder window
	set command to "clear; cd " & pathList
end tell

tell application "System Events"
	set isRunning to (exists (processes where name is "iTerm3	"))
end tell

tell application "iTerm"
	activate
	set hasNoWindows to ((count of windows) is 0)
	if isRunning and hasNoWindows then
		create window with default profile
	end if
	select first window
	
	tell the first window
		if isRunning and hasNoWindows is false then
			create tab with default profile
		end if
		tell current session to write text command
	end tell
end tell

ip:

on alfred_script(q)
	tell application "iTerm"
	  tell the current session of current tab of current window
		write text "open -a 'Path Finder' ./"
	end tell
  end tell

end alfred_script

Hope that helps someone. I don't use the other commands so I can attest to those.

blackxored avatar Jun 15 '17 17:06 blackxored

It works for me , i just change "iTerm" to "iTerm2"

fi

on alfred_script(q)
  
  tell application "Finder"
    set pathList to (quoted form of POSIX path of (folder of the front window as alias))
    set command to "clear; cd " & pathList
  end tell
  
  tell application "System Events"
    -- some versions might identify as "iTerm2" instead of "iTerm"
    set isRunning to (exists (processes where name is "iTerm")) or (exists (processes where name is "iTerm2"))
  end tell
  
  tell application "iTerm2"
    activate
    set hasNoWindows to ((count of windows) is 0)
    if isRunning and hasNoWindows then
      create window with default profile
    end if
    select first window
    
    tell the first window
      if isRunning and hasNoWindows is false then
        create tab with default profile
      end if
      tell current session to write text command
    end tell
  end tell
  
end alfred_script

if

on alfred_script(q)
  tell application "iTerm2"
    tell the current session of current window
      write text "open -a Finder ./"
    end tell
  end tell
end alfred_script

aqiuxx avatar Apr 12 '18 16:04 aqiuxx

Yosemite 10.10.5

aqiuxx avatar Apr 12 '18 16:04 aqiuxx

when i run fi, display in debug log: [ERROR: action.applescript] { NSAppleScriptErrorAppName = Finder; NSAppleScriptErrorBriefMessage = "Not authorized to send Apple events to Finder."; NSAppleScriptErrorMessage = "Not authorized to send Apple events to Finder."; NSAppleScriptErrorNumber = "-1743";

Prometheusaim avatar Oct 16 '18 13:10 Prometheusaim

Ok so i have a solution that is not 💯but flipping good enough. I change the AppleScript in the fi command to this:

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
	
	tell application "System Events"
        do shell script "open -a iTerm " & pathList
	end tell
end alfred_script

All this does is let OSX do the heavy lifting. sure this looses options like using the current window or tab but it gets my an iterm on my finder directory and i can deal with all the other stuff.

infn8 avatar Nov 21 '18 16:11 infn8

@infn8 I totally slept on this, I'm sorry. I took that idea after a comment in #23 and went with it. This should solve this issue since the apple script doesn't mention iTerm at all. Long time coming 😇

LeEnno avatar Jun 12 '23 20:06 LeEnno