Scripts

Toggle Dark Mode

If you're on macOS Mojave, this AppleScript is a more convenient way to toggle Dark Mode on and off.

I have one on the Dock, while I'm deciding if I do like the Dark Mode or not...

 

tell application "System Events"
	tell appearance preferences
		set dark mode to not dark mode
	end tell
end tell

Sleep

Until some time ago you could send your (desktop) Mac to sleep just pressing the power button; this behaviour has been removed now, but I found it to be quite convenient (on a 27" monitor moving to AppleMenu and selecting the "Sleep" command is too many clicks away for my habits).

So I keep a small AppleScript on the bottom-left corner of my Desktop: a double-click and... night night.

The code is quite simple:

tell the application "Finder" to sleep

pwd

If you mess around with hidden folders, system files, complex paths and swap from Terminal to the Finder, getting on the fly the current path of the frontmost window can be useful.

I keep this AppleScript on the Finder's toolbar, so it's available to any open window. Click on it and you will get its path and a button so you can copy it into the clipboard if you need to paste it somewhere else.

Here is the code:

tell application "Finder"
	set theWin to window 1
	set thePath to (POSIX path of (target of theWin as alias))
	display dialog thePath buttons {"Clipboard", "OK"} default button 2
	if the button returned of the result is "Clipboard" then
		set the clipboard to thePath
	end if
end tell

Convert to JPG

There are many ways to take a screenshot, but I prefer to go the easy way, keep the defaults how they are and adjust if needed. Sometimes I just need the screenshot to be in .jpg instead of .png.

Drop any image onto this Automator script and a jpg copy of it will be created (original is kept untouched).

Works with any other png, of course, and other formats too.

Open Folder

Why would anyone need a script to open a folder? Well, you need one if you want:

  1. an alias to Dropbox with a custom icon
  2. an alias to a folder on iCloud with a custom icon

You should know now how much I like customization and consistency. My Desktop shows in clean order my Volumes and after them two folders: Dropbox and my "Personal" folder on iCloud (with all the files not specifically bound to an app). And I like these folders to look like my Volumes: squares with rounded corners.

You will find here two AppleScripts that need to be customized:

tell application "Finder" to open folder "Users:username:Library:Mobile Documents:com~apple~CloudDocs:YourFolder" of startup disk

Change "YourFolder" to the name of your folder and "username" to your username.

For Dropbox:

tell application "Finder" to open folder "Users:username:Dropbox" of startup disk

This, assuming that the Dropbox is at the root of your Home folder (otherwise, change the path accordingly). Same as above for your username.

I also provide four custom icons:

  • Dropbox, light
  • Dropbox, blue
  • iCloud, blue
  • iCloud, orange