OS X – Scheduled files cleanup

Do You like Your ~/Downloads folder ? Is it always clean and well organised ? Mine never was … Over time it got so messy that it was easier to download something again that look for it in ~/Downloads…

I came up with an idea of scheduled folder cleanup, but because in OS X cron is not available by default I had to figure it out the OS X way.

First I wrote a script for cleanup in ~/bin/download-cleanup :


find /Users/[username]/Downloads -mtime +30 -print0 | xargs -0 rm -rf

This script looks for files older than 30 days and deletes them.

Now lets schedule it. Create file under ~/Library/LaunchAgents/pl.jusz.gen.DownloadCleanup.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-/Apple/DTD PLIST 1.0/EN" "http:/www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

You can now register Your plist file with launchd:

launchctl load ~/Library/LaunchAgents/pl.jusz.gen.DownloadCleanup.plist

If You want to manually invoke Your script through launchd:

launchctl start pl.jusz.gen.DownloadCleanup.plist



Cheap Time Capsule alternative using Ubuntu 12.10

Why spent $260 for Time Capsule, when You can make Your Ubuntu to act exactly the same? Here is how to do this.

First we’re gonna install couple of things that we need for further setup:

sudo apt-get install avahi-daemon libavahi-client-dev libdb5.3-dev \
db-util db5.3-util libgcrypt11 libgcrypt11-dev

Then download the latest version of Netatalk – Open Source AFP fileserver. We’ll use netatalk 3.* because its much easier to setup as Time Capsule. Because the latest version in repositories is 2.2.* we’ll have to compile it by ourselves.

tar xvjf netatalk-3.*.tar.bz2
cd netatalk-3.*
./configure --with-init-style=debian --with-zeroconf
sudo make install

When everything is installed it’s time to do some configuration. First we’ll create a dir when we we’ll store all time machine backups.

sudo mkdir /media/Time-Machine/

Then we’ll add new user called timemachine, who will own this directory

sudo adduser timemachine
# here comes some data that You'll have to fill up
sudo chown -R timemachine. /media/Time-Machine

Now we’re ready to edit /usr/local/etc/afp.conf

; Netatalk 3.x configuration file

; Global server settings

uam list = uams_guest.so, uams_dhx.so, uams_dhx2.so,

; [Homes]
; basedir regex = /xxxx

; [My AFP Volume]
; path = /path/to/volume

[Time Machine MediaPC]

path = /media/Time-Machine
time machine = yes

Then it’s time to configure avahi-daemon which will propagate our Time Capsule over the local network.
Let’s create /etc/avahi/services/afpd.service

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
    <name replace-wildcards="yes">TimeCapsule %h</name>

So let’s start everything

sudo service netatalk start
sudo service avahi-daemon start

# to ensure that netatalk will start on boot
sudo update-rc.d netatalk defaults

Now You can enjoy your fresh Time Capsule alternative for the cost of HDD :)

This guide should also work for Raspberry Pi, XBMCbuntu, Debian 6.

OS X: SSH tunnel in OS X Lion

Best and easiest way to secure your internet connection in untrusted network (like free Wi-Fi hotpot)?
SSH Tunnel :)

You’ll just need a shell account on a server and You’re ready to go. Fire up Terminal:

ssh -D 8080 -f -C -q -N user@yourserver.com

-D 8080 : This basically does a lot of dynamic stuff and makes it behave as a SOCKS server. Of course you could use any non privileged port here (above 1023).
-f : This will fork the process into the background after you type your password.
-C : Turns on compression.
-q : Quiet mode. Since this is just a tunnel we can make it quiet.
-N : Tells it no commands will be sent. (the -f will complain if we don’t specify this).

Then open System Preferences -> Network.

Select active network connection, click Advanced... -> Proxies -> SOCKS Proxy.

In SOCKS Proxy Server enter localhost:8080 and You’re DONE! :)

Now You can check if Your IP Address changed in www.whatsmyip.org.

Mail.app: problem with IMAP synchronization

This problem occurred to me yesterday. Mail.app couldn’t synchronize with IMAP account properly. During investigation I’ve found out that it’s creating same one message in Drafts folder in a loop. After 1 day there was around 1300 messages… pretty cool, yeah? Nope, not really… Quick research and I’ve found a solution – remove Mail.app‘s offline cache. Fire up Terminal and do:

rm -rf /Users/$USER/Library/Mail/V2/[IMAP-account]/.OfflineCache

Mac OS X Lion 10.7.4