PDA

View Full Version : AppleScript Problems




CaptainZap
May 28, 2007, 03:57 PM
I'm trying to create an AppleScript app so that when I add it to Xcode > Preferences > File Types, it opens the file in Vim, inside of iTerm (I chose iTerm over Terminal because of the looks and I like the tabs).

So far I have made a droplet, so that when I drop files onto it, it opens what was dropped, inside of Vim in iTerm. And when I set it up so that files in Xcode open up with this Application, it just pops up in the Dock for a slit second then disappears.

Here is the Script...
on open vFile
copy (POSIX path of (vFile as alias)) to vimPath

set vimCommand to "vim '" & vimPath & "'"

tell application "iTerm"
activate

make new terminal

tell the first terminal
launch session "Vim"

tell the last session
set name to "Vim - " & vimPath
write text vimCommand
end tell

end tell
end tell
end open

Any ideas?



SC68Cal
May 28, 2007, 08:48 PM
You might need to switch over to a bash shell script command for it to open it up.

For your deepest nested loop

tell the last session
set name to "Vim - " & vimPath
write text vimCommand
end tell

Have the commands done in the BASH environment:

do shell script "Vim" and put your vimPath in after that.

I'll try it out and see what I can do, though I don't have iTerm. I'll just substitute the regular old terminal.

SC68Cal
May 28, 2007, 08:52 PM
Okay, very bare bones. Using Terminal instead of iTerm. What's important is the "do shell script" on line 6.


on open vFile
copy (POSIX path of (vFile as alias)) to vimPath
tell application "Terminal"
activate
tell the first window
do script "vim " & vimPath
end tell
end tell
end open


Hope this helps

CaptainZap
May 28, 2007, 09:02 PM
Hmm, I don't think you quite understood my question. But I think I got it to work using a different way, thanks anyways.

tyr2
May 28, 2007, 09:11 PM
Hmm, I don't think you quite understood my question. But I think I got it to work using a different way, thanks anyways.

Could you post how you've got it working? I'm interested to do the same thing.

CaptainZap
May 28, 2007, 09:18 PM
Well instead of using iTerm and Vim, I just decided on using Vim.app, since I just found out there is a neat tab function and you can split the screen. But what I did for it, was first I changed Xcode to open the files with Vim.app and all I have to do is type ":tabnew" and it will open a new tab then open the file from Xcode. Just PM me for more details.

But my Applescript still allows you to drag files into it and it will open it in Vim inside of iTerm.

tyr2
May 29, 2007, 12:22 AM
I'd not come across Vim.app before, cheers for that it looks interesting.

CaptainZap
May 29, 2007, 03:01 PM
Vim.app is pretty neat, I did a quick Googled, and I found you you can set it up so Cmd + T opens a new tab and Cmd + W closes the current one, and you can also cycle through the tabs. Pretty sweet.