Category Archives: Mac

Web server in OSX (Apache2, dammit!)

There’s an Apache2 in OSX!!!

Apache2! It’s been awhile since I touched httpd.conf… so many memories… ūüėČ

It’s all described in this tutorial:¬†

It’s dead simple – see/edit¬†/etc/apache2/httpd.conf to find or set DirectoryRoot (mind directory access rights) and run “sudo apachectl start” (stop, restart).

To enable user websites, add following to etc/apache2/users/USERNAME.conf :

<Directory "/Users/USERNAME/Sites/">
Options Indexes Multiviews
AllowOverride AuthConfig Limit
Order allow,deny
Allow from all

and then it’d be served as¬†

Also, generating self-signed certificates:

And adding them to OSX keychain:

And you’d need to put them into¬†/private/etc/apache2/ssl/ and (potentially) edit¬†/private/etc/apache2/extra/httpd-ssl.conf and enable (uncomment)

Include /private/etc/apache2/extra/httpd-ssl.conf


LoadModule ssl_module libexec/apache2/

in /etc/apache2/httpd.conf

and run “apachectl restart” as root.

Champagne for all!

/   \
||  |
||  |    .    ' .
|'--|  '     \~~~/
'-=-' \~~~/   \_/
       \_/     Y
        Y     _|_

Exporting Apple Mail filters to Sieve format

What’s this?

It’s a script (in AppleScript) that goes through all Apple Mail filters and converts them to Sieve filters, so you could go server-side on email filtering


The answer is, as usual, “because I’m lazy” – I’ve accumulated a fair bunch of Apple Mail filters along the way, and converting them manually wasn’t much fun. And I found no working option to convert it on the Internet.

Code and disclaimer

Code is available at:

feel free to clone, submit your patches etc.

NOTE that this is validated with a quite limited use case – in my filters, I mostly match against subject and sometimes against CC/To, so it definitely has some issues with other fields. Please review / try loading the results first and don’t disable all your Mail filters right away.

Exporting Mail filters

Just run that script – it will ask you if you want to use disabled filters as active (useful to re-export after you have already disabled Mail filters), then if you want to disable Mail filters (useful when you’re certain in your Sieve filterset), and then where to save the results.

Was it fun?

Well… the answer is “look at the code”. On the one hand, writing in AppleScript is quite unlike writing in most of the “conventional” languages – some constructs are very different, some seem more natural, others more awkward. On the other, loops management reminded me of programming Turing machine – I mean, using THIS as “continue”, really?!

So to conclude – I think it was, as any unusual experience is fun in it own (however peculiar) way. And it’s the “proper way” for the case – you deal with official API, not parsing the XML (which I could, because Mail rules are stored in XML files) because there’s no way to foretell where the source would move or how its structure would change eventually. Mail API is way less likely to do so.


Some Sieve-related resources FTR:

What’s next?

Have a beer!

Bluetooth sound quality issues in OSX

I love the wireless technologies, I truly adore them. One thing that bothers me about Bluetooth though is sound glitches and jumps – it works pretty for some time, and then all of a sudden it starts twitching, small fractions of it missing. Minor, but very annoying.

This is actually broader issue than OSX – for instance, no smartphone works with a Bluetooth headset perfectly if I keep the phone in my jeans pocket. It all goes well and nice till it gets jumpy out of the blue – and then back normal again.

Now with Mac it’s a bit different – at some point sound starts twitching, and it goes on then till I re-initiate Bluetooth connection. And it was kinda alright till it got me. One speculation I found over the Internet was connection bitrate is too low and needs to be raised with this command line:

defaults write “Apple Bitpool Min (editable)” 60

because default is 40. So I have tried that, it didn’t help much, so I assumed that’s not the right solution and forgot about it. And after a while I did what I should have done right away – I restarted Bluetooth on Mac. And… speaker stopped working at all – it connected, but failed with something like “compressed stream is unacceptable”. Since I forgot I mangled Bluetooth settings, first thought was my speaker broke.¬†And it was kinda alright (it has wired input, quite old and I don’t use it every day) till it got me.

So I googled up the error message and results stroke me with remembrance. Changing the value in aforementioned command to 53 (that was highest suggested working rate) and… it’s all good now! Can’t say about twitches – they were sporadic and never ocurred right away – but at least I got it back working.

One note: that command is for user space, don’t run it with sudo (no harm there, just wouldn’t work).

Disable OSX Mail app from popping up on calendar events

As (I believe) many OSX fellas, I connect my Google calendar with OSX calendar to receive all the notification in pop-up form – and just to have all the event a tap away. However when event reminder fires, OSX Mail app starts jumping in anxiety, yelling “Oh! Oh! You forgot to add your email! Do it, do it now!” – and that’s annoying because, well, I don’t use that app and I have no intention to.

The solution is simple (for a downside, read on):

sudo chmod 000 /Applications/

that’d just disable Mail app from being able to launch. It’s dirty, yes – but it’s that famous “good enough” kung-fu. If you need to get Mail app back to launchable state, well, just undo the spell with 755 permissions.

Now on that downside: you have to do this with each system update, because either app access rules or file itself get restored on update – that’s how I got to writing this, because I faced the problem again after an update. How to cope with it? Well, just do it again – updates are seldom enough. That’s how I’m gonna deal with it anyway.

Remove duplicates from iTunes playlist

UPDATE: Script could be found on BitBucket now –¬†

If one adds music to iTunes playlist by dragging them files in (without moving to iTunes library), one might end up with a fair number of duplicates. And one might get frustrated about it.

ALso, one might even go and solve it, and then share for other suffering fellas Рlike this:

NOTE: playlist should be sorted by name. And it makes sense to export a playlist for backup reasons – for I give no warranties here.

Code is included to the image – but let it rest below as well. FTR to launch/edit it, run AppleScript Editor (use Spotlight) – it’s simple but nice tool to write AppleScript apps.


tell application "iTunes"
display dialog "Gimme playlist name" default answer ""
set plName to the text returned of the result
set curPl to user playlist plName -- current playlist
set dupes to {}
set prevTrack to {"", 0}
set trackNo to 1
repeat with aTrack in every track of curPl
set curTrack to {get name of aTrack, get time of aTrack}
if curTrack = prevTrack then
set the end of dupes to trackNo
end if
set trackNo to trackNo + 1
set prevTrack to curTrack
end repeat
set dupePos to 0
repeat with dupe in dupes
set rmTrack to dupe - dupePos
-- log rmTrack
delete track rmTrack of curPl
set dupePos to dupePos + 1
end repeat
set dialogLine to "Deleted " & (count dupes) & " dupes in " & plName & " playlist"
display dialog dialogLine buttons {"OK"}
end tell