Shell script to get path of application in MacOS


Posted by Jaime | Posted in Tip | Posted on 10-08-2011

Tags: , , ,

Here is a shell script that finds an application on my hard drive using a nifty call to Finder using AppleScript:

result=`exec osascript <<EOF
tell application "Finder"
	set thePath to (POSIX path of (path to application "Doxygen"))
end tell
echo $result

UNIX tip of the day


Posted by Jaime | Posted in Coding, Tip | Posted on 07-07-2011

Tags: , , , ,

Thanks to my coworker for showing me this:

pbpaste | c++filt | mate

I use this to take a really long text output from GDB and de-mangle the code into something I can read.

I copy the output in the GDB console to the clipboard and the command takes those contents and pastes the results into TextMate.

How to duplicate one file … a lot


Posted by Jaime | Posted in Tip | Posted on 10-06-2011

Tags: , , , ,

I had to duplicate a file… over a thousand times, for a test.

For the MacOS, I created a shell script to do this:

#!/usr/bin/env bash
# I'm passing in the filename as a parameter to the shell script,
# which is accesible through $1
for (( i = 0; i < 2000; i++ )); do
	cp -p "$1" "${i}_$1"

On Windows, I opened a command window ( Start -> Run -> cmd.exe [Hit enter] ), changed directories to my pictures folder, then typed:

for /L %f in (1,1,2000) do copy MYDOG.JPG %fMYDOG.JPG

Thanks to my co-worker for showing me the Windows tip!


Using DTerm and the shell to rename files


Posted by Jaime | Posted in Tip | Posted on 06-12-2010

Tags: , , ,

I download files from my bank that have some really long name to them and at the end of the name, is the date.

The date is not formatted, of course, and I wanted to rename the files easily, without manually parsing out the string.

Now on my computer, I have DTerm and TextMate at my disposal. So, I created a shell script that would take two parameters: the path to the file and the file name to parse:

#!/usr/bin/env bash
echo "Starting script with parameters $1 $2"
cd $full_path
mv $file_name "${year}-${month}-${day}_statement.PDF"

Now that I saved the script in my Documents folder, I can go to where my file is downloaded and type:
/Users/jaimerios/Documents/ "$PWD" mysuperlongfilename20101014.PDF

To make things easier, I use TextExpander to type out the command for me in DTerm, then hit “Command+Shift+V” for DTerm to type out the name of the currently selected file.

Then Voila! The file has been renamed!