LeEnno/alfred-terminalfinder

fi in iterm2 doesn't work

dustookk opened this issue ยท 26 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}";
}

Thanks for reporting.

  1. Are you using the current workflow version?
  2. If so, when did it stop working?
  1. yes.
  2. when I press fi, nothing shows up : )

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

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

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

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.

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

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

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.

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!

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.

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}";
}

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

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.

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.

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

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.

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.

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

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

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

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.

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

Yosemite 10.10.5

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";

infn8 commented

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.

LeEnno commented

@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 ๐Ÿ˜‡