A quick word on modern BASH

0

Posted by Jaime | Posted in Coding | Posted on 30-05-2017

Tags: ,

Here’s a page that has some useful tips for modern BASH scripting: http://www.davidpashley.com/articles/writing-robust-shell-scripts/

OmniGraffle supports UNIX keyboard commands

0

Posted by Jaime | Posted in Tip | Posted on 20-08-2012

Tags: , , ,

Well, at least ctrl+a and ctrl+e. I haven’t tried anything else, but I was surprised to find out that these even work within OmniGraffle.

Shell script to get path of application in MacOS

0

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:

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

Passing parameters to shell scripts

0

Posted by Jaime | Posted in Coding | Posted on 28-01-2011

Tags: , ,

I recently fell in love with TextMate.

For me, programming 24/7, TextMate helps me edit files that would normally be a pain with the standard editors on the market.

Now, with that being said, I started making a lot of Bash shell scripts to automate building projects with Xcode and delivering the binaries for testing.

I actually had a couple of scripts to handle certain portions of the different builds, since the project was made up of many projects not just one big monolithic giant project.

Well, I needed to send my Bash scripts some parameters and I was scratching my head on how…

Well, it’s not so hard sending and getting those parameters. Check out the link below.

Reference
http://bashscript.blogspot.com/2009/11/how-to-pass-arguments-to-shell-script.html

Using DTerm and the shell to rename files

0

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"
 
full_path=$1
file_name=$2
year=${file_name:(-12):4}
month=${file_name:(-8):2}
day=${file_name:(-6):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/rename_file.sh "$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!

References:
http://tldp.org/LDP/abs/html/string-manipulation.html