Jump to content

File Action "Open Terminal Here" stopped working since Catalina


Recommended Posts

- macOS Catalina 10.15.3 (19D76)

- Alfred 4.0.8 [1135]

- iTerm2 Build 3.1.5

 

It has been a while that "Open Terminal Here" stops working. If I remember right it was after I upgrade to Catalina.

 

The file action  "Open Terminal Here" now just opens a terminal tab (as default), not cd to the folder specified.

Edited by ladychili
Link to post
Share on other sites

@ladychili check the macOS Security & Privacy > Privacy > Automation settings to ensure that Terminal / iTerm is selected for Alfred. If it is, then try un-ticking and re-ticking these.

 

You may also need to check your specific integration with iTerm in Alfred's Features > Terminal is correct or up to date.

 

Cheers,

Andrew

Link to post
Share on other sites

Glad I’m not the only one having this issue, as it gives another point of reference.


I’ve been experiencing something like this for a while, but across all Terminal actions, including inside Workflows. Two important differences from this report:

  • I’m on Mojave.
  • It doesn’t fail every time.


I didn’t yet have the chance to do a deep dive and figure out the exact steps to make it fail or succeed, which is why I hadn’t mentioned it yet. Either way, my suspicion was already that the fault lies in iTerm2 itself, which has a Python API as a replacement to AppleScript and thus might not be noticing breakage in the latter.

 

@Andrew I’ve been meaning to ask (I wanted to think a bit more about it first, but since we’re on the subject): on Alfred’s Terminal functionality, could we have other languages available in Custom? It might be wise to consider arbitrary languages due to iTerm’s Python API, but at least JXA would be a huge step. AppleScript-only is a pain, especially when considering the de fact scripts for calling iTerm2 from Alfred still have bugs and the repo is abandoned. I’d like to provide new maintained scripts to the community but it’d be easir for me to leverage the iTerm2 JXA scripts I’ve already built for other purposes.

Link to post
Share on other sites

@Andrew Thank you for the reply, problem solved after I re-granting those permissions to Alfred. It occurs to me that many apps re-asked for permissions after the OS upgrade. 

 

@vitor  Below is the AppleScript I used for iTerm2 at Terminal Custom Integration, hope it can help a bit. 

 

on write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as string
		set the open_target_file to open for access file target_file with write permission
		if append_data is false then set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file


on alfred_script(q)
	
	-- Write the command to run to a file. This is done because Applescript quoting is impossible to get right, esp. for backslashes.
	set tmp_dir to path to temporary items as string from user domain
	set applescript_alfred_file to tmp_dir & "alfredscript"
	set alfred_file to POSIX path of applescript_alfred_file
	write_to_file(q & return, applescript_alfred_file, false)
	
	-- Create this file, which prevents iTerm2 from restoring a saved window arrangement.
	do shell script "touch ~/Library/Application' Support/iTerm/quiet'"
	
	-- Test cases:
	-- 1. iTerm2 running, has windows open. Should open a new window for Alfred command.
	-- 2. iTerm2 running, no windows open. Should open a new window for Alfred command.
	-- 3. iTerm2 not running, set to restores arrangement. Should not restore arrangement but open a new window for the Afred command.
	-- 4. iTerm2 not running. No windows to restore. Should open a single window for the Alfred command.
	-- 5. iTerm2 not running. Has windows to restore. Restores windows and then opens a new window for the Alfred command.
	
	-- Compose a script. This is necessary because compiling in a 'tell application' command causes the app to be launched, which would happen prior to the creation of the quiet file.
	set theScript to "tell application \"iTerm2.app\"
    if (exists current window) then
        tell current window to create tab with default profile
		tell current session of current window
			write contents of file \"" & alfred_file & "\"
		end tell
    else
		create window with default profile
		tell current session of current window
			write contents of file \"" & alfred_file & "\"
		end tell
	end if
    activate
end tell"
	
	-- Invoke the script.
	run script theScript
	
	-- Clean up
--	do shell script "rm -f ~/Library/Application' Support/iTerm/quiet' /tmp/alfredscript"
end alfred_script

 

 

 

 

Link to post
Share on other sites
On 3/2/2020 at 5:12 PM, vitor said:

I’ve been meaning to ask (I wanted to think a bit more about it first, but since we’re on the subject): on Alfred’s Terminal functionality, could we have other languages available in Custom?

 

Hmm I'm going to have to investigate why I made it AppleScript only in there, it may just be a completely legacy thing. I'll add a note, and if there is no significant reason, then I could likely add in arbitrary scripting.

Link to post
Share on other sites
5 hours ago, Andrew said:

Hmm I'm going to have to investigate why I made it AppleScript only in there, it may just be a completely legacy thing. I'll add a note, and if there is no significant reason, then I could likely add in arbitrary scripting.

 

Thank you. Even JXA would already be a huge help (was it even a thing yet when you first added the feature?).

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...