Here is a AppleScript to open files from Finder in Vim. Personally, I use Helix command-line editor (hx
), but you can replace it with vim
, it doesn’t matter.
on run
tell application "Terminal"
do script "hx"
activate
end tell
end run
on open theFiles
set fileList to ""
repeat with aFile in theFiles
set filePath to POSIX path of aFile
set fileList to fileList & space & quoted form of filePath
end repeat
tell application "Terminal"
do script "hx" & fileList
activate
end tell
end open
Sometimes when I drag multiple files, say 4, on the app’s icon, everything is fine. A single Terminal window appears with 4 Helix buffers.
But sometimes it works weird. There are multiple Terminal window appear, and some buffers are in one window, whereas other buffers are in another window.
I aksed ChatGPT, DeepSeek and Claude, and they say this is because macOS often split dragged files into groups, which means on open
handler is fired twice. But is this true? The so-called AI ofter say misleading things.
And how to workaround this, in a concise and beautiful way?
A side note. I’m not sure, but it seems the splitting is somehow related to date-created. I have three identical txt files with the same permissions, and the only difference between them is date-creation. The files are 2022.txt, 2024.txt, and 2025.txt. If I drag all of them at once, 2022 and 2024 are opened together, but 2025 is opened in another Terminal window, even if I drag not three but just two files, e.g. 2022 and 2025.
Here is DMG with them:
test/files.dmg at main · johnmapeson/test · GitHub
(I use DMG and not ZIP or TAR because it’s the only way I know to preserve
date creation
.)