Skip to content

Instantly share code, notes, and snippets.

@alsolovyev
Last active February 21, 2024 12:32
Show Gist options
  • Save alsolovyev/838c84c0e3efd3e6e55c94e8c7fe7c33 to your computer and use it in GitHub Desktop.
Save alsolovyev/838c84c0e3efd3e6e55c94e8c7fe7c33 to your computer and use it in GitHub Desktop.
A script to open a file in nvim by right-clicking on it
on run {input}
if (count of input) > 0 then
set {filePath, fileName} to getPathAndName from input
set cmdCd to "cd " & quoted form of filePath
set cmdNvim to "nvim " & quoted form of fileName
tell application "iTerm"
if exists window 1 then
tell current window
create tab with default profile
tell current tab
tell current session to write text cmdCd
tell current session to write text cmdNvim
end tell
activate
end tell
else
create window with default profile
tell current window
tell current session to write text cmdCd
tell current session to write text cmdNvim
activate
end tell
end if
end tell
else
display dialog "No items in the input list."
end if
end run
on getPathAndName from someItem
tell application "System Events" to tell disk item (someItem as text)
set absPath to the POSIX path of container
set {fileName} to {name}
end tell
return {absPath, fileName}
end getPathAndName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment