AppleScript Problems

Discussion in 'Mac Programming' started by CaptainZap, May 28, 2007.

  1. CaptainZap macrumors regular

    Joined:
    Jan 17, 2007
    #1
    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?
     
  2. SC68Cal macrumors 68000

    Joined:
    Feb 23, 2006
    #2
    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.
     
  3. SC68Cal macrumors 68000

    Joined:
    Feb 23, 2006
    #3
    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
     
  4. CaptainZap thread starter macrumors regular

    Joined:
    Jan 17, 2007
    #4
    Hmm, I don't think you quite understood my question. But I think I got it to work using a different way, thanks anyways.
     
  5. tyr2 macrumors 6502a

    tyr2

    Joined:
    May 6, 2006
    Location:
    Leeds, UK
    #5
    Could you post how you've got it working? I'm interested to do the same thing.
     
  6. CaptainZap thread starter macrumors regular

    Joined:
    Jan 17, 2007
    #6
    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.
     
  7. tyr2 macrumors 6502a

    tyr2

    Joined:
    May 6, 2006
    Location:
    Leeds, UK
    #7
    I'd not come across Vim.app before, cheers for that it looks interesting.
     
  8. CaptainZap thread starter macrumors regular

    Joined:
    Jan 17, 2007
    #8
    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.
     

Share This Page