I’ve managed to make a small AppleScript that gets the selection from Safari & a link and posts it to RSS.chat. I already had a script that copied the selection and put it and a link on the clipboard ready to paste into a blog post. I’d also tried out posting to RSS.chat with bash from TextMate.

Putting the two together was fine until I selected anything complex. Converting that into a blockquote with a citation gave me lots of errors when I passed it to the shell. Finally I asked Claude. This brought jq into the mix. I already had that installed.

Currently I am using it on my own install of rss.chat, thinking of using it to gather interesting links for later consideration.

I run the script, and quite a few others from FastScripts. Not sure if my script be of use to anyone else but here it is.

I occasionally use AppleScript to avoid repetitive tasks. I quite enjoy writing scripts. My scripting tend to follow the guess and check procedure. It can be weeks or months between these efforts so I need to look up the library or search for many basic things1.

In my part time job, I quite often report findings or issues with the Glow Blogs system. In doing so I need to remember to include: computer model, OS version Browser and Browser version. This is quite simple but requires a few clicks and a bit of typing. I thought today I might create and AppleScript to do this for me.

I then thought I might use Claude.ai to get me started2. I used the prompt:

Can you give me a n applescript that will report on the current model of mac, the version of the OS and the current application & version?

I’ve noticed that AI doesn’t seem to be bothered with my constant typos!

The first script threw an error when I tested it. So I copied the error and the line it came from and sent it back to Claude. Another error. This continued through 10 versions. Sometimes I broke off to test an idea of my own or check the AppleScript Library and reported that to Claude.

This began to feel a bit like my usual process of testing, checking and reading. But a good bit quicker. We finally got there. I just added a line to copy to the clipboard and put the script in the Script Library so I can call it with FastScripts3.

For some reason I thanked Claude:

You’re welcome! The final script successfully gets:

1. The Mac’s hardware model

2. Current OS version

3. Active application name and version

Just for future reference – we went through several approaches before landing on the most reliable method using osascript to directly query the application’s version. This ended up being more robust than trying to get the version from file metadata or application paths.

Let me know if you need any modifications or have other AppleScript questions!

At this point I only had one free message left. So I asked Claude to refactor the script into a shell script. This it did with one error. With no more messages left, a search produced a fix pretty quickly. I ended up with this.

  1. This is true of all the scripty type things I do. Except for HyperCard which I used every day for years. ↩︎
  2. I’ve been using free versions of AI for a while now. A few times a week. Mostly for school things. Creating a text for pupils, or questions on a text. Claude is my current fav for scripting. ↩︎
  3. I think FastScript is one of my favourite mac applications. It is very handy for this sort of script as you can either select it from FastScripts menu or give it a keyboard shortcut. The Front application, which we are interested in, stays at the front. ↩︎

As I’ve mentioned before we use Apple Notes a lot in our class. If the class are writing, unless there is a need for formatting or layout, I often ask the pupils just to stick to notes.

Notes are easily AirDropped to me when I need to collect work and both pupils and myself can organise them in a fairly simple manner.

Occasionally I want to print the pupils work. Notes, reasonably enough, only lets you to print one note at a time. I wondered if there was AppleScript that would help. I found Export Apple Notes via AppleScript which exported a folder of notes to a new TextEdit document. I altered it to:

  • Allow you to choose a folder from Notes.
  • Export to an html file on disk.
  • Provided page breaks so that the notes would each print on their own page.

Not particularly pretty, I guess I could work on the styles a little.

You need to be in my lucky position of having a mac in your classroom. Mine uses the same account as my iPad which helps me organise thing a lot.

Here is the code, I suspect it could be improved. Even if you don’t use AppleScript is easy enough to run. Open the AppleScript editor, create a new script, paste the code below in and hit run. You will be asked to choose a folder and then name an html file. The file will be created and opened with your default browser.
You then can print.

set htmltop to "<!doctype html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\">
<title>Notes Export</title>
<style>
@media print {
hr {
page-break-after: always;
}
}
</style>
</head>
<body>"
set htmlbottom to "</body>
</html>"
tell application "Notes"
activate
set x to (name of every folder whose name is not "Notes")
set foldertoexport to (choose from list x) as string
if folder foldertoexport exists then
set output to ""
repeat with aNote in notes in folder foldertoexport
set noteText to "<!-- ### Start Note ### -->
"
set noteText to noteText & ("<h1>" & name of aNote as string) & "</h1>
"
-- set noteText to noteText & ("<p>Creation Date: " & creation date of aNote as string) & "</p>"
-- set noteText to noteText & ("<p>Modification Date: " & modification date of aNote as string) & "</p>"
set noteText to (noteText & body of aNote as string) & "<hr>
"
set output to output & noteText
end repeat
set thehtml to htmltop & output & htmlbottom
set theNewFile to choose file name default name foldertoexport & "-notes.html"
set myFile to open for access theNewFile with write permission
write thehtml to myFile as «class utf8»
close access myFile
else
display dialog "not likly to happen"
end if
end tell
tell application "Finder" to open theNewFile

I got a request from a teacher who wanted to download a years worth of images from a Glow Blog (for end of year slideshow).

Although there are plugins that can do this these are not available on Glow Blogs. I was stumped apart from going through the site and downloading them 1 by 1. But after a wee bit of thinking I though I’d try using the REST API via AppleScript.

The REST API will list in JSON format the media:

http://johnjohnston.info/blog/wp-json/wp/v2/media/

Look at that in FireFox for a pretty view.

JSON Helper is

an agent (or scriptable background application) which allows you to do useful things with JSON directly from AppleScript.

So I can grab the list of media from a site in JSON format use appleScript to download all the files.

The script I wrote is not great, you can’t download from a particular year, but a quick look at the JSON will help in working out how many files to download.

I am sure there are more efficient ways to do this and I’ve only tested on a couple of site, but it seems to do the trick and might be useful again sometime.

Continue for the script: