Categories
Mac

Display advanced info in AirPort Utility

Since version 6 AirPort Utility has sucked. That’s why I kept an old copy of version 5.6 around: I like the fact that it doesn’t assume you’re dumb, like 6 and later versions do.

However, there’s a way to display some useful information about the connected clients in an easy way (hat tip Marco Dalprato): hold ⌥ (option) while double clicking on the AirPort base station you want to inspect.

AirPort Utility 6 made more useful

Categories
Mac

Connect to CrashPlan running in a FreeNAS jail using OS X

I’ve got CrashPlan running on my FreeNAS-based home server1, and it is going smoothly. It was kinda pain to get it working (java problems, CrashPlan upgrades, and stuff like that), but now it has been behaving itself for a few months.

I don't know why I feel i should make these images in every post. Sorry.

Still, every now and then I want to check on it to keep track of the upload progress, change a few settings and what not.
Since I also run CrashPlan on my Mac, it has always been a pain to reconfigure everything each time I wanted to control the instance running in the FreeNAS jail and then back to the Mac’s.
Also, a while back CrashPlan changed their daemon-GUI authentication scheme: previously you just had to connect to the proper port on the right IP, now it also needs a token that seems to change randomly. It looks like it changes whenever the backup service restarts, but I’m not really sure, as my Mac’s doesn’t seem to change nearly as often, and my Macs power cycles way more than my server, but that’s an argument for another day. Also, the port seems to be randomly changing as well, so don’t even get me started about that.

Anyway, I had to find a way to get the current token, put it in the proper CrashPlan GUI’s config file (which is /Library/Application Support/CrashPlan/.ui_info in OS X), launch the GUI, do my business, close it and the put everything back.

To accomplish that, the first thing you need to do is to enable SSHd in the jail: connect to your main FreeNAS, type jls to get a list of all the running jails, and take note of CrashPlan’s JID.

[root@zeus] ~# jls
   JID  IP Address      Hostname                      Path
     1  -               VBox                          /mnt/Archivio/jails/VBox
     2  -               couchpotato_1                 /mnt/Archivio/jails/couchpotato_1
     3  -               crashplan_2                   /mnt/Archivio/jails/crashplan_2
     4  -               plexmediaserver_1             /mnt/Archivio/jails/plexmediaserver_1
     6  -               sonarr_1                      /mnt/Archivio/jails/sonarr_1
     7  -               transmission_1                /mnt/Archivio/jails/transmission_1

As you can see, mine is 3. So let’s connect to the jail: jexec 3 csh (which means launch the csh shell on jail number 3).

Now you need to edit the jail’s /etc/rc.conf, in order to have the SSH server start with the jail. You can do so by adding the following line:

sshd_enable="YES"

(Or, if present and set to NO, just switch it to YES and save the file.)

Now just start the SSH server with service ssh start.

The next step is to add a user to the jail: we’ll be using this instead of root to connect to it. Run adduser and follow the instructions. In the rest of this post the user will be luca. Why? Well, because reasons2.

Now switch to the newly created user and create a .ssh directory in the home directory.

su luca
mkdir ~/.ssh

Now it’s a good time to copy the SSH public key of your Mac’s account, which you can find in ~/.ssh/id_rsa.pub. Copy it to the clipboard:

cat ~/.ssh/id_rsa.pub | bcopy

Back to the jail, paste it into the ~/.ssh/authorized_keys file:

echo "PASTE HERE YOUR PUBLIC KEY" >> ~/.ssh/authorized_keys

After all this hard work, we can finally test our setup. Open a new terminal window/tab and try to connect (you’ll find the jail’s IP address in the FreeNAS web UI).

ssh luca@192.168.1.78

Of course replace luca with your user and the IP with the correct one. If all worked as it should, you’ll be asked (for the first time only) to accept the server’s RSA fingerprint, and then you’ll be logged in without needing a password.

Now that we have a working SSH server, let’s get to the main part of all this madness. Here’s my script, crashplan_remote.sh.

First, adjust line 8 and 9 replacing the placeholder user and IP with the one you set earlier.

Make the script executable (chmod +x /path/to/crashplan_remote.sh) and put it somewhere in your PATH (may I suggest /usr/local/bin?).

Before launching the script, I feel I should explain what it does. First of all it makes a backup of your current local GUI settings (root privileges needed here), then it connects to the jail, retrives the current token and port to connect to the service, puts them in the .ui_info config file (again, root required), creates an SSH tunnel that is used to avoid having the CrashPlan service directly exposed to the network (by default it listens on 127.0.0.1 only). Once the tunnel is established, it launches the CrashPlan GUI, which will now communicate with the remote service. Once you close it, the tunnel will be closed as well and the local settings will be put back in place (root privileges required).

If you’ve read this far, you just have to launch crashplan_remote.sh and the script will take care of everything for you. It will even tell you what it is doing, here’s the output I get:

[luca @ MBP-Luca-eth in ~ ✅ ] $ crashplan_remote.sh
Password: (I entered my password here, required by sudo)
PORT: 4343
TOKEN: th1sC0d3-iZn0-tTh3-C0rR-3ct0N3Y0L0OO
.ui_info updated, creating SSH tunnel...
SSH tunnel established, launching CrashPlan Desktop
CrashPlan Desktop closed, terminating SSH tunnel...
Exit request sent.
Restoring local CrashPlan settings...
  1. Nothing fancy: a Pentium G2020, 8 GB of RAM and 4×4 TB WD Red’s in RAIDZ1. I know RAIDZ1/RAID–5 is dead, but thanks to ZFS I should only loose those files that happen to suffer from UREs, and the important stuff is backed up elsewhere. I only regret I didn’t go for 5×4 TB drives, it should have improved speeds.
  2. My name is Luca. My user is called luca.
Categories
Mac

How to get rid of a stuck unread message badge on OS X

Having our messages (iMessage and SMS) available on our Macs is great, however sometimes we get an unread badge that can’t seem to go away, no matter how hard we look for the unread message, it is just not there1.MessagesBadgeIn many cases, however, the solution is simple, and you don’t even need to reboot.

  1. Quit Messages
  2. Restart the dock, either using Activity Monitor or running killall Dock from the terminal

Many thanks to crazyj on Stack Exchange for sharing this easy trick.

  1. Pro tip: you can see which conversations have unread messages by right clicking on the Messages icon. Not that opening these would help getting read of the stuck badge, however.
Categories
Mac

Send files to Evernote from Hazel

I finally decided that I want to move most of my paperless workflow to Evernote. Its search feature make it more convenient than going through a bunch of folders in Dropbox, and I guess that the fact that the bonus space I had gained through Dropbox’s Space Race has expired gave me the final push I needed to move my stuff.

So, I made a thing.

Evernote_secret_mailI called it sendToEvernote. It’s a Python script that mails the files you want to send to Evernote to the personal address every Evernote user gets after signing up. You can find yours in the “Account Info” section of the app, and you should make sure you keep it secret, otherwise you’re likely to get random junk in your notebooks.

You’ll find sendToEvernote on GitHub. Download it.

I’ll spare you some details about the script (you can find everything in the README file), and just go through what you need to do to get up and running with Hazel.

  1. Download the mailer Python module:
    sudo easy_install mailer
  2. Edit your email settings at the top of the script
  3. Make it executable:
    chmod +x /path/to/sendToEvernote.py

    PROTIP: drag the file into your terminal window instead of typing the path manually.

  4. Add a “Run shell script” action (embedded script) to your Hazel rule, and enter the following:
    /path/to/sendToEvernote.py "Notebook name" "$1"

Hazel Evernote rule That’s it.

Categories
Mac

Delete undeletable files on OS X

Today I found myself stuck: I couldn’t delete a directory from my Mac, no matter what I tried, sudo or not.

Undeletable file
Turns out, for some reason the schg flag was set on that folder. schg, or “system immutable” flag, prevents even root from doing anything with that file. Fortunately, root is allowed to remove that flag, and then delete the file.

sudo chflags noschg undeletable_file_or_folder
sudo rm -rf  undeletable_file_or_folder

Problem solved.

(Always be careful copying and pasting sudo rm -rf commands from the internet.)

Categories
Mac

Recover Ableton Live’s recording after a crash

Last night, I was recording a podcast using Ableton Live as usual, and my Mac kindly decided that it was time for a kernel panic. This left me with a few unusable .aiff files, that couldn’t be opened in Live, in QuickLook or any other app.

CorruptedAIFF

It looked like I was screwed. Enter Audacity, one of the ugliest applications available for OS X. It has a great feature: it can open raw PCM data, and it was able to successfully recover the whole recording. You just have to click on File/Import/Raw Data and select the corrupted AIFF file. A window like this will pop up:

AudacityRawSettings

You’ll have to adjust some settings to match Live’s. I used 44.1 kHz 16 bit mono, but make sure to check your Ableton recording settings to get yours. Don’t worry if you set them wrong, it won’t touch your original file, it will simply not play correctly in Audacity.

Once you have successfully imported your track, you can export it from Audacity in just about any format you might need.

Categories
Linux Mac

Automatically download iOS firmwares

IPSW

Today I discovered that it takes quite a while to download an iOS IPSW, and when you need IPSWs, you are always in a hurry. So I made this little script that checks for a new release using icj.me’s API and downloads it. The comments in the script itself should make it pretty easy to use.

I added the script to my home server’s crontab, and scheduled it to run at 1 am every night, with a low bandwidth limit not to hog my connection.

Note: to use this on OS X you will have to either install wget (from sources, binaries, brew, ports, whatever) or edit the script to use curl.

Categories
Mac

Run Hazel rule based on the day of the week

Hazel-for-Mac-iconI LOVE HAZEL.

Now that I made that clear, let’s get into the actual stuff.

As many of you will know, Hazel is a great Mac utility that lets you automatically do stuff to files. You can move files based on their name/size/extension/you name it, and do a bunch of cool stuff with them, without ever having to write a single line of code.

Today I needed to write a rule that would act based on the day of the week a file was created1.

Turns out, Hazel can do that (not much of a surprise, huh?), but this time I didn’t find it particularly intuitive how to do it. You have to use the “Occurs after” function on the “Created date” (or any date, actually). In this example, this rules will only run on files that have been created after 00.00 on Mondays only, i.e. any file created on Mondays.

Hazel rule day of week(Don’t be confused by the weird names on the “day of week” submenu, they’re just the Italian names for the days of the week.)

The cool thing is that you can select more than one day, so as always Hazel is very flexible.

  1. I use a Sony ICD PX333 Voice Recorder to record classes, and I want to rename them based on the day of the week, since what we do depends on the day of the week
Categories
Mac

Clipboard new-line format when copying from Preview

Today I helped my brother with a Keyboard Maestro macro he needed. Basically, he wanted to take some text from a PDF created by Notability, which inserts new lines to have text flow around images, and remove these new lines.

Preview

Pretty easy, I thought: pbpaste to tr and remove \n. Nope. For some reason, maybe some old Mac OS 9 heritage, when copying text from Preview new lines are saved as carriage returns, i.e. \r.

This stupid behavior means that if you try to pbpaste something which contains line breaks in your terminal, you only get the last line. You can view the full output by replacing \r with \n:

pbpaste | tr '\r' '\n'

This lame thing had me waste some time, so I hope this short post makes your life easier.

P.S.: The full command I had my brother put in Keyboard Maestro is:

pbpaste | tr '\r' ' ' | pbcopy

Followed by a Paste action. This replaces line breaks with spaces and pastes the result.

Categories
Mac

WeMo Control Workflow for Alfred

 

UPDATE October 2014

Belkin seems to have changed the ports the Wemo’s server listens on, so I updated the workflow. Download and replace your current install (you’ll have to set the IP again). Wemo-Switch Today I had some spare time, so I decided to hack together a simple Alfred Workflow to be able to control my Belkin WeMo Switch (Amazon US, Amazon IT) from my Mac. TL; DR: Download and enter WeMo IP in the “Script Filter” block. Type wemo to launch it. After some googling, I found this nice bash script that allowed me to send commands to the WeMo. It was then just a matter of encapsulating it into a nice Alfred wrapper, and it was relatively easy. WeMo-WorkflowIn order to use my workflow, just download it, install it, open it in Alfred and enter your WeMo’s IP address into the “Script Filter” block. If you also want to use keyboard hotkeys to turn on/turn off/toggle your WeMo, type in the IP in the lower “Run Script” block as well. Open up the Hotkey blocks to edit them. Now that you’re all set, type wemo to get some info about your WeMo. Press enter on the status row to toggle it. Or you can also type wemo on or wemo off to quickly control your switch. The workflow currently supports only one device. I’d love to add support for multiple ones, but I only own one WeMo so it’d be very hard for me to develop the workflow without being able to test it. The Amazon links above are both affiliate links, if you buy a WeMo through one of them you don’t pay any extra and I get a few cents from Amazon.