Search

Passwords, and time...

AppleScript is here to save you time by automating trivial tasks, but it also can save you money by allowing you to create the small utilities that you'd otherwise not hesitate to spend a few bucks on. Mind you, I have nothing against independent software developers. I just think that if you can learn to do it yourself, you should choose to learn...

It is possible to create passwords on macOS. Open Keychain Access, select "New Password Item" and click on the key shaped icon at the bottom right. You get all sorts of options and end up with a password that you nicely crafted. But really, do we need all that icing? What we need is a robust password that the machine will remember and that you can reinitialize when needed.

Using the system I introduced in the previous post I created this trivially small utility that I can launch any time I need a new password:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set myPassword to (do shell script "openssl rand -base64 24")
display alert " New password: " & myPassword
set the clipboard to myPassword

The display tells me what the password is, and whatever I do the password is put into the clipboard so that I can paste it right away. To be able to launch this script from Spotlight, I saved it as an application.



Also, there is no "international" clock application bundled on macOS. So here is my way to check that I am on time when I need to deliver a project in a different time zone. Time zones are a problem when you work with different clients in totally different places. I don't need to have the clock running all the time either, I just need to check the time sometimes.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set Vancouver_time to ((current date) - 17 * hours)
set Paris_time to ((current date) - 8 * hours)
set Takamatsu_time to (current date)

display alert ("Vancouver:" & " " & time string of (Vancouver_time) & " - " & short date string of (Vancouver_time) & "

" & "Paris:" & " " & time string of (Paris_time) & " - " & short date string of (Paris_time) & "


" & "Takamatsu:" & " " & time string of (Takamatsu_time) & " - " & short date string of (Takamatsu_time))

The format is optional, you can tweak it as you wish.



Et voilĂ . The AppleScript used here is trivial enough that there is no need for comments. Also I decided to use a different format for AppleScript keywords: I'm using an underline so that I know what the keyword boundaries are. The hint is given in Learn Applescript from Apress. It's very nice to have that visual hint when you read your code.