As already talked about, the error is from focusing on iTerm’s present window
, since there is not one (you closed it). I haven’t got iTerm, however the resolution for that will be to test if it has any home windows, and if not, make or open one. Additionally observe that Automator’s enter
is a record.
If you happen to use Terminal’s do script
command, it is going to open in a brand new window (until in any other case specified) so you do not have to take care of that. If all you’re utilizing Automator for is the script and arguments, an everyday AppleScript utility can be utilized, which is a bit more versatile. Since purposes could be command-dragged to the Finder window’s toolbar, you can too skip setting file sorts to open with the app, it might get the present choice.
The next is an everyday AppleScript droplet that information could be dropped onto, it may be double-clicked to simply ask for file objects, and clicking the toolbar icon (if positioned within the Finder window) will move the present choice to the app. It might even be known as from the command line, all of which is able to open a brand new Terminal window operating Helix (or Neovim). Save the script as an utility; I’m assuming that you’ve Helix (or Neovim) configured.
use framework "Basis"
use scripting additions
on run args
strive
set selectedFiles to {}
if args is in {present utility} then -- app double-clicked or 'open -a' with --args choice
set processList to (present utility's NSProcessInfo's processInfo's arguments) as record
if (depend processList) > 0 then set selectedFiles to remainder of processList -- first merchandise is the executable
else if args isn't in {"", {}, lacking worth} then -- osascript with arguments
set selectedFiles to args
finish if
if selectedFiles is {} then
inform utility "Finder" to if (get home windows) isn't {} then -- strive present Finder choice
set selectedFiles to get choice as alias record
finish if
if selectedFiles is {} or (((path to me) is in selectedFiles) and ((depend selectedFiles) is 1)) then -- select dialog
activate me
set selectedFiles to (select file of kind "public.textual content" with a number of picks allowed)
finish if
finish if
open selectedFiles
on error errmess
show alert "Error in 'run' handler" message errmess
finish strive
finish run
on open droppedFiles -- objects dropped onto the app
doStuff(droppedFiles)
finish open
to doStuff(theFiles) -- primary
set arguments to ""
repeat with anItem in theFiles -- an inventory of information will load in a standard window
strive
if (path to me) isn't in {contents of anItem, POSIX path of anItem} then -- skip the app if path is within the record
set anItem to quoted type of POSIX path of anItem
set arguments to arguments & anItem & area -- construct argument string
finish if
on error errmess
show alert "Error in 'doStuff' handler" message errmess
finish strive
finish repeat
inform utility "Terminal"
activate
do script "hx " & arguments
finish inform
finish doStuff