Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CaptainZap

macrumors regular
Original poster
Jan 17, 2007
170
0
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...
Code:
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

macrumors 68000
Feb 23, 2006
1,642
0
You might need to switch over to a bash shell script command for it to open it up.

For your deepest nested loop
Code:
			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

macrumors 68000
Feb 23, 2006
1,642
0
Okay, very bare bones. Using Terminal instead of iTerm. What's important is the "do shell script" on line 6.

Code:
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

macrumors regular
Original poster
Jan 17, 2007
170
0
Hmm, I don't think you quite understood my question. But I think I got it to work using a different way, thanks anyways.
 

CaptainZap

macrumors regular
Original poster
Jan 17, 2007
170
0
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.
 

CaptainZap

macrumors regular
Original poster
Jan 17, 2007
170
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.