Posts filed under 'terminal'

Copy and continue copying large files over file sharing

In my experience, there is often a flaky slow server at work that contains vital files on it. This is fine when you need to retrieve files that are small, but what happens when you need to copy a large file? Most of the time these servers don’t support ftp protocol and if you are on a Mac, you have to connect via smb (Samba) to the share and start copying and hope you don’t have to stop, because if you stop the copy, the file disappears from your machine and you can’t resume it.

However, I stumbled on this gem the other day:

curl -C - -O file:///Volumes/samba_share/file/path/here.txt

Basically, curl allows you to copy a file with url syntax in the terminal. The capital “O” tells curl to copy the file to your desktop with the same name as the file on your server, and the capital “C” tells it to continue where it may have left off. You can monitor the download in the terminal window. If you need to leave work and finish the copy the next day, simply enter the command again in the terminal and it will pick up the copy where it left off.

Add comment Thu, 2008 Mar 20, 11:05am

Bizarre Clipboard Problem

This has happened to me a couple of times using TextMate (probably has occurred
elsewhere without consequences that I noticed). Every once in a long while, I will not be able to copy text into TextMate. I do this on a regular basis to analyze XML and JSON responses from the server for the application I work on at VmWare, copying FireBug response data into TextMate running either the XML tidy or a script I set up to tidy up the JSON data, so copying into TextMate is very important to me. Sometimes, however, it just doesn’t work. I can copy/paste in TextMate, but not from another application to it. As it turns out, this has to do with the system pasteboard server. Essentially, you can fix the problem by restarting this service. See: http://wiki.macromates.com/Troubleshooting/CantPaste for more details.

Add comment Wed, 2008 Jan 09, 11:47am

Textmate: Run Command in Terminal

Maybe this exists already - I couldn't find it, so I just wrote it. Of course, I am putting this here as code, but one day I'll publish a new bundle of TextMate commands which includes this and some of the other ones I've put together. I was looking around today for some commands that I might use to augment the Perforce bundle -- specifically, I needed a dialog. What I found was some references to the use of CocoaDialog, which is pretty handy. Another use I had envisioned for dialogs in a TextMate command was to be able to run terminal commands *in* the Terminal. After all, sometimes you would like to have something run and dump its output right there in the Terminal, rather than in a new TextMate document or something like that. The Apple Terminal is pretty nice for what it is, and its much better than the Linux KDE terminal, the Windows terminal, and the poor bastard Windows Cygwin terminal.
To set up this in TextMate, open the Bundle Editor and create a new Command. Set the command to Save "Nothing", Input "None", and Output "Discard". Give it a key command if you like, and leave the Scope Selector blank. In the Command(s) field, paste the following:

CODE:
  1. #!/bin/bash
  2.  
  3. # First use CocoaDialog to pop a dialog to get
  4. # the command you would like to run.
  5. res=$(CocoaDialog inputbox --title "Run Command in Terminal Window" --informative-text "Enter the command here:" --button1 "Okay" --button2 "Cancel")
  6.  
  7. # if the cancel button was pressed then exit
  8. [[ $(head -n1 <<<"$res") == "2" ]] && exit_discard
  9.  
  10. # set the command string to what was entered
  11. command=$(tail -n1 <<<"$res")
  12.  
  13. # create our applescript which will launch a
  14. # new Terminal window if there is not one running
  15. # and otherwise run the command we want in the
  16. # current running Terminal window
  17. aplscr="tell application \"System Events\" to set terminalRunning to (exists process \"Terminal\")
  18. if (not terminalRunning) then
  19. tell application \"Terminal\" to activate
  20. tell application \"Terminal\" to do script \"$command\"
  21. else
  22. tell application \"Terminal\" to activate
  23. tell application \"Terminal\" to do script \"$command\" in front window
  24. end if"
  25.  
  26. # execute the applescript
  27. osascript -e "$aplscr" &>/dev/null &

In a nutshell, as the comments indicate, we capture the contents of the field in the dialog that is opened, and stick them into the applescript that we want to run. The applescript part checks to see if there is already a Terminal session window open, and will run the command in the Terminal. If Terminal isn't open, then it launches it. You (or maybe me in the future) could fancy this up a bit if you wanted by having the Terminal change directory to the directory in which the file you are working on exists. Not sure that is always desirable though for my purposes.

Enjoy it. (if you're a total geek you probably will, at least in principle)

Additional work needed:
1. Escape quotes (you have to do that manually now).
2. Have Terminal spawn a new window if it is already running but has no open windows. (need to check for window count in addition to process running)

Add comment Tue, 2006 Dec 12, 11:55pm

OSX Terminal Hack - .DS_Store files

This only prevents .DS_Store files from being written on network shares, but nonetheless, quite handy. In the terminal, enter the following:

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

Add comment Tue, 2006 Nov 07, 9:33am

Alias adds to OSX Terminal

Since my latest job has gotten me using the Terminal in OSX much moreso than I used to, I've had to bone up on my unix (and linux) commands. Unfortunately, when OSX sets up your user account, there is no .bashrc file (that I could find) for doing things like setting up handy command aliases. For example, by default, typing "ls ~" in the terminal will give you a listing of your home directory, but will not list any "invisible" files (those that start with "."). So, it would be nice to have "ls" actually call "ls -a" every time.

So, to accomplish this, you need to create 2 files, ".bashrc" and ".bash_profile" in your user directory. The contents of the .bash_profile file need to be as such for starters:

. ~/.bashrc
ENV=$HOME/.bashrc
export ENV

Then, the contents of .bashrc need to be something like this:

PATH=$PATH:$HOME/bin:/usr/local/bin
alias ls="ls -a"
SHELL=/bin/bash

This will get you started. If you have any questions beyond that, do some online searches for .bashrc and shell configuration. (I'm no expert, I just figure out what I need to do to get stuff done...)

Add comment Mon, 2006 Nov 06, 10:18pm

Textmate Open to New Project Window

Something that has bothered me for a while in TextMate is that in the project drawer you can open a single file in a new window. Often, I like to open a new scratch project window to edit certain files that may also be in the project itself. A simple solution to this is to create a new TextMate command (I called it "Open from Drawer" since it allows you to simply open a single file, even though it opens in the same project window). Set the Save to "Nothing", and the Input and Output to "None" and "Discard". In the Commands field, enter the following:

#!/bin/sh
osascript -e "tell application \"TextMate\" to open POSIX file \"$TM_SELECTED_FILE\""

You can set a Key Equivalent if you like. When done, select a folder in your project drawer. If the folder is a file system folder (rather than a group), the script will spawn a new project window containing all the files in that folder. Selecting a "group" folder will do nothing (may work on that one later...).

Add comment Thu, 2006 Nov 02, 6:46pm

As2Api and RubyScript2Exe (darwinized)

I recently sat down and took a look at as2api, which seems to be the most recommended JavaDoc exporter for actionscript. Once I had everything figured out, it seems to work fine, and I'm sure there are some little nuggets that I haven't quite figured out yet, which I'm looking forward to figuring out. (read more for the skinny and darwin downloads)

However, for those of you out there in Mac OSX land, I wouldn't recommend downloading the current version listed on the site for OSX, entitled "as2api-allinone-osx-0.4.sit" in the downloads section. I think that it is missing files, or that it just doesn't work correctly at all. I would recommend instead downloading the first link for "as2api-0.4.tar". The downside of downloading this version is that there is no OSX command line executable in there, so you have to run the Ruby script "ruby as2api.rb packages --classpath classpath" which works just fine.

Honestly, I don't know enough about ANT scripts yet to know if you can run Ruby scripts from an ANT script target, so I used rubyscript2exe, another handy little application to convert the Ruby scripts into a mac command line executable. (Incidentally, and to add a little geek comedy to this post, you have to install the Pascal compiler and compile a piece of the rubyscript2exe library in order to run it...so I had to compile one application in order to create another one...).

Anyway, I have included below 2 downloadables in this post. The first is the command line version of as2api that is compiled from the package that you can download as Ruby code from the as2api site. The down side is that you cannot tweek the css and html templates that are part of that code; the up side is that you can actually use it as a command line executable, which is entitled "as2api_darwin". You can used it exactly as you would the as2api.rb Ruby script.

PlasticWare Downloadable ::
Darwin Executable of As2Api (JavaDoc for Actionscript) (Sep. 5, 2006)
Download (~4.5mB) :: as2api-0.4.zip

The second downloadable I have included here is the rubyscript2exe download, altered to include the eee_darwin file that I compiled from the pascal source on my mactel laptop in OSX 10.4.7, and repackaged using tar2rubyscript.rb, which was also necessary to get it running properly. I have also included the example hello world script "hello.rb" from the tutorial, which you can use to test the code and make a hello world exe.

PlasticWare Downloadable ::
RubyScript2Exe with eee_darwin for OSX environment (Sep. 5, 2006)
Download (~1.1mB) :: rubyscript2exe.zip.gz

Both of these pieces of software are released by their proper creators under the GNU License, and I have included the source and license for each as well, as posted on their sites. Please download judiciously, the executable for as2api package is 4.5 mb.

7 comments Tue, 2006 Sep 05, 5:55pm

OSX Graceful SMB Dismount (umount)

For the time being - until I get some extra code cash, I've switched back over to Eclipse, as I've been doing a good bit of Flash and Javascript coding, and my dev box is a Windows 2003 virtual machine on a server somewhere in California, on which I can also handily run Eclipse. So, until I really optimize my process, I'm sidelining TextMate a bit (as my trial period is about done). So, I've been writing some Ant build scripts to optimize the process (more on that perhaps a bit later), and have configured a couple of targets in my flash project to auto-install my distribution tar.gz file onto my dev box.

This works great most of the time -- I connect to the dev VM via a windows share using an SMB connection from my Mac, so the Ant scripts point to the remote box as /Volumes/D$. Unfortunately...

...my router is flaky and times out my cable connection about 2-3 times a day, rendering my connection to my dev VM non-existent. Here is where the slight problem occurs - the mount-point on the Windows box is D$, so when OSX makes an SMB connection, it creates a D$ temporary folder in the /Volumes directory on the Mac. When the connection is unexpectedly broken, the clean-up to remove that directory fails, and when the share is reconnected, OSX creates a new version of the directory, as "D$-1" (or -2, -3, etc.), which breaks the Ant scripts.

The solution, simply, is to open the Terminal after such an unexpected disconnect, and perform the command:

sudo rmdir /Volumes/D$

to remove the unmounted directory.

I have tried to connect directly to the smb share in the terminal utilizing the specific share directory:

sudo mount_smbfs -W workgroupname //username@ipaddressofserver/D$ /Volumes/D$

but unfortunately, you have to su in the terminal (switch to root user) in order to access the contents -- otherwise the directory is read only. When running the Ant scripts from Eclipse, you don't have root user permissions, and copying to the remote machine fails. Anyone have any thoughts on this?

2 comments Wed, 2006 Aug 16, 11:46pm


Site Decryption

info = { PlaIns: "the section of the PlasticStare site, the digital external brain-repository of Ryan Todd, whose brain otherwise occupies space in San Francisco, CA", ryota: "mungified version of ryan's name", haikuBio: "robotic from birth. hears sounds - listens to music. makes pixels act." }

Calendar

July 2008
S M T W T F S
« Jun    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Posts by Month

Posts by Category