In this article it helps if you already know a little bit about AppleScript, though that’s not completely necessary. Near the end of the tutorial I show how to invoke the AppleScript code using Scala, so feel free to skip down to there if you just want to see that — you can always read the stuff at the top for reference later.
If you run into a problem where a Scala shell script won’t run on MacOS — it hangs indefinitely without doing anything — hopefully this bug report will help. The solution is to change this line at the beginning of the Scala shell script:
exec scala -savecompiled "$0" "$@"
exec scala -nocompdaemon -savecompiled "$0" "$@"
I just had this problem with Scala 2.12.x and Java 8 running on MacOS 10.14.4, and I can confirm that adding
-nocompdaemon solved the problem for me.
If you need to copy a directory on Unix/Linux and want to preserve the date/time information while copying the directory and files, use the
-p option to save the date/time information, and the
-r option to copy the directory properly. For instance, I just used this
cp command to copy a directory named OldDir to a new directory named NewDir, while retaining all of the date/time file information:
If you want to create a shell script so you can change between MacOS dark mode and light mode from the Terminal (Unix) command line, put this source code in a file and name it something like dark:
osascript -e \ 'tell application "System Events" to tell appearance preferences to set dark mode to not dark mode'
Then make that file executable, and make sure it’s on your PATH. Now you can type
dark to toggle back and forth between dark mode and the regular light mode:
In my spare time back in 2011 I created a Java version of the old Unix/X-Windows “Xeyes” application. If you ever used Xeyes, you know it as a set of eyes that are displayed on-screen, and follow the mouse cursor as you move it around.
Now in 2019 I just brought it back to life, and here’s a 56-second video that shows how it works:
As a brief note to self, this is how I compiled/built an Android application (APK) from the MacOS command line and then ran it in an emulator. I include both my application- and system-specific notes, as well as the more generic commands I found at this Android.com URL:
As a brief note to self, I like the way the TODO tag is highlighted when using TextMate, so I dug around to see how it worked so I can make other words be highlighted the same way it is. The short answer is that in TextMate, click the Bundles menu, select Edit Bundles, then scroll down to select TODO near the bottom of the list, then Language Grammars and TODO. The last few steps are shown in the image.
My MacBook recently told me I was running out of disk space. I knew that the way I was backing up my iPhone was resulting in me having multiple copies of photos and videos, so I finally decided to fix that problem by getting rid of all of the duplicate copies of those files.
So I wrote a little Scala program to find all the duplicates and move them to another location, where I could check them before deleting them. The short story is that I started with over 28,000 photos and videos, and the code shown below helped me find nearly 5,000 duplicate photos and videos under my ~/Pictures directory that were taking up over 18GB of storage space. (Put another way, deleting those files saved me 18GB of storage.)