AppleScript JSON Project
Been thinking a lot today about trying to get a new open source project started to build a fully functional JSON library entirely in AppleScript. This project would be similar to the ASObject or ASTwitterLibrary projects that I have worked on in the past and would add a much needed feature to AppleScript on OS X.
If you are interested, or know someone who would be interested in helping code this project, please let me know!
Random Shootings
"You want to know why. This may sound cynical, but here's why.
It's because of the way the media reports it. Flip on the news and watch how we treat the Batman theater shooter and the Oregon mall shooter like celebrities. Dylan Klebold and Eric Harris are household names, but do you know the name of a single victim of Columbine? Disturbed people who would otherwise just off themselves in their basements see the news and want to top it by doing something worse, and going out in a memorable way. Why a grade school? Why children? Because he'll be remembered as a horrible monster, instead of a sad nobody.
CNN's article says that if the body count "holds up", this will rank as the second deadliest shooting behind Virginia Tech, as if statistics somehow make one shooting worse than another. Then they post a video interview of third-graders for all the details of what they saw and heard while the shootings were happening. Fox News has plastered the killer's face on all their reports for hours. Any articles or news stories yet that focus on the victims and ignore the killer's identity? None that I've seen yet. Because they don't sell. So congratulations, sensationalist media, you've just lit the fire for someone to top this and knock off a day care center or a maternity ward next.
You can help by forgetting you ever read this man's name, and remembering the name of at least one victim. You can help by donating to mental health research instead of pointing to gun control as the problem."
Giving Bash A Try Statement
Enter Bash… It does a wonderful job of a lot of things when working strictly in the shell. However, it doesn’t have a try statement. You can attempt to ask permission or simply go ahead and run your command (hoping that it doesn’t’ error) but what if you want to keep track of whether or not a command did in fact error and do something about it?
The following is two examples of how to trap an error for a command in bash:
someCommand 2> /dev/null;
# Do the command but don’t show an error to the user if one occurs
if [ “$?” -ne 0 ]; then
echo “An Error Occurred”;
fi
OR
someCommand;
# Show the error to the user, if any, and then do something about it
if [ “$?” -ne 0 ]; then
echo “An Error Occurred”;
do_something_about_it
fi
And that is it… now you can have a “try” statement in bash.
Processing Pseudo Arrays In Bash
I had an epiphany last night regarding the processing of an array as full lines of text in bash. Normally in bash an array is delimited by any whitespace character(space, newline, tab, etc.) however, I specifically wanted to process an array with the delimiters only being newline characters.
My first attempt at doing this lead me down the path of setting the internal field separators (IFS) in bash to the newline character, then creating my array, and finally resetting the IFS back to its default. This worked but made the script rather hard to read and, to be honest, I just didn't like doing it that way.
Then, last night, I realized that there is another way to process individual lines in bash that I could use on a “pseudo array". Thus, I have arrived at the following code conclusion:
pseudoArray=`cat `;
# Use echo to turn the string variable into a pseudo array
echo "$pseudoArray” | while read line; do
echo "$line”;
echo "----"; # To show I am processing each line in turn
done
And that, my friends, is how to take data that is delimited by a newline character and process it as an array in bash!
ASObject 0.8.1 Released
Version 0.8.1 of ASObject contains the following updates:
- Workaround - Bug with keychain scripting in 10.7 and later! Please download Scripting Additions Package
- Fixed - Bug with Previous_Application method!
- Added - Write_To_Log method now logs to system log file as well as specified file!
Coding Underway
- Lyricatcher
- ASObject
- ASTwitterLibrary
- LittleBirdOSX
See you around the web!
ASTwitterLibrary 2.2
A Stop By My Blog
I know many of you are wondering when I will begin working on all my scripting projects again and believe me when I tell you that they have not fallen by the wayside. I still work on them as often as I can, even if it is only an hour or two a week. I do hope to be releasing some updates to all of the scripts soon that will fix many of the bugs that I have had to simply bandaid in the recent months. Keep watching and refreshing your pages, the updates are on their way.
Also, as a side note, my wife has started a blog of her own at BrokenPencil.me! She is going to be sharing a bunch of yummy food recipes and anything else she can from our new lives in Denver! Check it out… you will like it!