Command Line Arguments in NewtonScript and NEWT/0 ¬

2012-01-21

Still being a daily Newton user as well as a developer, I’ve always wanted to learn NewtonScript. I’ve got a PowerMac 9500 that’s been configured for Newton OS development for quite some time and I’ve got a couple projects in mind, but I just never seem to get around it.

I’ve also had NEWT/0, an open source, cross-platform NewtonScript interpreter, installed for a while. Since it can run NewtonScript scripts from the command line like any other interpreter, I decided I’d like to know if it was possible to get the command line arguments from NewtonScript so I could eventually write some local scripts to get myself familiar with the syntax & functions (therefore less of a learning curve when I finally get around to writing some actual Newton packages). After a point in the right direction from Matthias Melcher and a lot of digging through the NEWT/0 source code, I finally figured out how to do so.

Here’s a quick NewtonScript script that can be run through NEWT/0 to print out the command line arguments you pass to it:

#!/usr/bin/env newt

Print("'_ARGV_ exists? ");
if GlobalVarExists('_ARGV_) then Print("Yes.\n") else Print("No.\n");

foreach slot, value in GetGlobalVar('_ARGV_) do Print(slot && ":"
&& value && "\n");

I doubt there are many, if any, out there that are interested in doing this, but—who knows?—maybe somebody else will start scripting in NewtonScript too. (Expect to see some more NewtonScript-related news around here in the future.)

Twitter Statuses Badge 0.7.1 Released ¬

2011-08-16

Or, this should’ve been done nine months ago.

When I released v0.7 of my Twitter Statuses JavaScript Badge back in November of last year, it was right around the time that Twitter was rolling out their new ‘snowflake’ status ID generator which was going to have some implications for languages such as JavaScript. Unfortunately, I didn’t become aware of this until I started seeing random issues with status IDs a couple months later. More unfortunately, I’m only getting around to applying the minor tweak to fix this, and a minor issue with applying the ‘last’ class when there’s only one LI element, now.

Without further ado, I present v0.7.1! Please accept my apologies for sitting on this issue for so long and let me know if you have any questions, comments, or feature requests. Also, the source code is on GitHub.

FYI – I started developing a major update back in March, including a few frequently requested features. Hopefully I’ll get that polished up sometime this year.

tools-osx 2011-06-02 ¬

2011-06-02

I’ve updated my collection of Mac OS X command line tools with improvements to the trash tool:

  • trash can now list trash contents across all volumes (with a disk usage total) as well as empty the trash (including a secure empty option; both emptying operations require confirmation).

Note: Obviously, the new version of trash is now destructive. I have tested and use this myself, but I cannot guarantee it won’t securely erase your entire hard drive if it encounters some odd edge case and I cannot be held responsible for that. So, use at your own risk and keep backups!

Go download them all (clipcat, eject, swuser, and trash) or get the source code on github!

sde_newsletter v0.5 ¬

2011-03-28

I’ve got a very minor update to the sde_newsletter Textpattern plug-in. v0.5 word-wraps HTML & text content in message/part bodies to 78 characters (if possible) to prevent hard wrapping at 998 characters which tends to badly break HTML content.

The sde_newsletter plug-in helps build HTML, text, or multipart email messages from Textpattern pages (although, technically, you can use any web-facing source HTML & text). It’s straightforward and very powerful when paired with newsletter/mailing list software.

Update: I discovered a minor bug parsing page title from HTML if the TITLE element contains line breaks. This has been resolved in v0.5.1.

tools-osx 2011-02-25 ¬

2011-02-25

There’s been a small addition to my collection of Mac OS X command line tools:

  • swuser gives you control of Mac OS X’s Fast User Switching from the command line, including options for switching to login window, user by name, or user by ID. Unfortunately, it’s not compatible with screen.

Go download them all (clipcat, eject, swuser, and trash) or get the source code on github!

An AppleScript to Invert the Display in Grayscale (And Another to Revert) ¬

2010-12-17

I’ve been doing a lot of early morning coding in bed, and have found that the only way I can do so without killing my eyes is to select “Use grayscale” as well as “White on Black” in the Universal Access preferences pane in System Preferences. This gives me a far more comfortable, inverted grayscale display. Unfortunately, it’s annoying and painful to initially set when my eyes are at their most sensitive.

I’ve modified a script posted on Apple Discussions to enable grayscale to also invert the display1 and saved it as a run-only application named Invert Display.app:

tell application "System Preferences" to activate
delay 1
tell application "System Events"
	tell process "System Preferences"
		click the menu item "Universal Access" of the menu "View" of menu bar 1
		click the radio button "Seeing" of the first tab group of window "Universal Access"
		if value of (checkbox "Use grayscale" of tab group 1 of window "Universal Access") is 0 then
			click the checkbox "Use grayscale" of tab group 1 of window "Universal Access"
		end if
		-- click the radio button "White on Black" of tab group 1 of window "Universal Access"
	end tell
	key code 28 using {control down, option down, command down}
end tell
tell application "System Preferences" to quit

Naturally, I also created another to restore the settings and named it Restore Display.app:

tell application "System Preferences" to activate
delay 1
tell application "System Events"
	tell process "System Preferences"
		click the menu item "Universal Access" of the menu "View" of menu bar 1
		click the radio button "Seeing" of the first tab group of window "Universal Access"
		if value of (checkbox "Use grayscale" of tab group 1 of window "Universal Access") is 1 then
			click the checkbox "Use grayscale" of tab group 1 of window "Universal Access"
		end if
		-- click the radio button "Black on White" of tab group 1 of window "Universal Access"
	end tell
	key code 28 using {control down, option down, command down}
end tell
tell application "System Preferences" to quit

I just launch them from Spotlight as needed. It’s a little distracting to see System Preferences launch and do it’s thing, but far easier than doing it myself when my eyes are being seared out of their sockets.

1 – Note that I’ve left the line for selecting the “White on Black” radio button in the script, but commented out, in case someone can catch the reason it throws an error. Since I’m in the preference pane anyway, it seems silly to use key code, plus I’d rather be able to verify it’s actually selected (like I do with the checkbox) so I’m not blindly toggling.

tools-osx 2010-12-08 ¬

2010-12-09

I’ve got a new release of my collection of Mac OS X command line tools for you, including:

  • trash correctly increments filenames (à la Finder) if the same filename already exists in your Trash instead of complaining that the file already exists. It also has a teensiest bit more logic regarding trash on the boot volume vs. other volumes.
  • eject now supports ejecting mounted network volumes and includes a -f option to force a stubborn volume to eject (to be used only in extreme cases).
  • clipcat is a new addition, submitted by David Kendal, which allows printing & concatenating of Text Clippings!

Go ahead and download them or grab the source code on github!