Black and White Extension Icons in Chrome

While reading the Noodlesoft forums I stumbled upon the buzz which pointed me to Adrian Logue post about how to get Black and White Extension Icons in Chrome.
There are two things “wrong” with the post from Adrian:
  1. He is describing setting this up in an older version from Hazel which doesn’t has support for Pixel Width and Pixel Height (or at least I have them as options)
  2. He mentions that the size of the Extension Icons are 19×19.
To me it looks like that the size of the Extension Icons are NOT only anymore 19×19, my extensions have a lot of different sizes, starting from 16×16 and ending at 128×128.
So I did write up a quick applescript which checks for specific sizes and also if the image is a square.
Note: 128 x 128 is a size also being used by the Apps display in Chrome, so maybe you want to remove that value form the list.
The top part of the script is quite useful for debugging in the applescript editor and doesn’t matter when you run it in Hazel.
-- This part is ignort in Hazel, so don't bother with it.
set theFile to choose file
hazelMatchFile(theFile)
-- The above part doesn't matter in Hazel
on hazelMatchFile(theFile)
set sizeList to {16, 19, 32, 48, 64, 96, 128}
tell application "Image Events"
launch
set my_image to open theFile
set my_dimensions to dimensions of my_image
close my_image
set my_x to item 1 of my_dimensions as integer
set my_y to item 2 of my_dimensions as integer
quit
end tell
if (my_x = my_y) then
repeat with size in sizeList
if (my_x = size as integer) then
return true
end if
end repeat
end if
return false
end hazelMatchFile
view raw gistfile1.ps1 hosted with ❤ by GitHub

Poor Man’s Sanebox

Call me cheap… but you can’t call me lazy.

Update: I forgot to mark the messages in the folders read, I added that to the script.
While Sanebox  is a great way to manage your inbox and remove a lot of pressure it just doesn’t cut it for me with my 30 mails a day.
So I came up to recreate the issue I liked the most from Sanebox, moving mails aside and bring them back in focus later again.
You can use mail rules for this, the only problem is that osx mail will not run rules on other folders than your inbox. But I found a solution on c-command which boils down to run a rule with every incoming mail, but on other folders (and they even did it because of sanebox..)
So this is what I did..
I took the applescript from c-command and made some changes to support @SaneTomorrow and @SaneNextWeek. Also because I have an Exchange and an GMail account I implement a try and on error to either use Inbox or INBOX depending on which format the inbox is.
And here is the script:
-- some parts taken from http://bit.ly/SaneBoxSpamSieve
-- original post on http://wp.me/p4WzrV-12
on accountAndMailboxNames()
-- Enter your account name, followed by a list of mailboxes for that account that should be filtered.
-- The account name comes from the "Description" field in the Accounts tab of Mail's preferences.
-- For example, this would filter the @SaneLater mailbox of Account 1:
-- return {{"Account 1", {"@SaneLater"}}}
-- And this would filter the @SaneLater and Other mailboxes of the Personal account
-- and the @SaneLater mailbox of the Work account:
-- return {{"Personal", {"@SaneLater", "Other"}}, {"Work", {"@SaneLater"}}}
return {{"Account 1", {"@SaneLater"}}}
end accountAndMailboxNames
on run
-- This is executed when you run the script directly.
my filterSaneMailboxes()
end run
using terms from application "Mail"
on perform mail action with messages _messages
-- This is executed when Mail runs the rule.
my filterSaneMailboxes()
end perform mail action with messages
end using terms from
on filterSaneMailboxes()
my logToConsole("Running Poor Man's Sanebox")
tell application "Mail"
repeat with _pair in my accountAndMailboxNames()
set {_accountName, _mailboxNames} to _pair
try
set _account to account _accountName
repeat with _mailboxName in _mailboxNames
my filterAccountMailboxName(_account, _mailboxName)
end repeat
on error _error
my logToConsole("Error checking mailbox “" & _mailboxName & "” from account “" & _accountName & "”: " & _error)
end try
end repeat
end tell
my logToConsole("Poor Man's Sanebox is done")
end filterSaneMailboxes
on filterAccountMailboxName(_account, _mailboxName)
set staledate to (current date) - (60 * days)
if _mailboxName contains "Tomorrow" then
set staledate to (current date) - (1 * days)
end if
if _mailboxName contains "NextWeek" then
set staledate to (current date) - (7 * days)
end if
tell application "Mail"
set _mailbox to _account's mailbox _mailboxName
try
set _inbox to _account's mailbox "Inbox"
on error _error
set _inbox to _account's mailbox "INBOX"
end try
with timeout of 60 seconds
set _messages to messages of _mailbox whose read status is false
end timeout
repeat with _message in _messages
set read status of _message to true
end repeat
with timeout of 60 seconds
set _messages to messages of _mailbox whose date received is less than staledate
end timeout
repeat with _message in _messages
set read status of _message to false
move _message to _inbox
end repeat
end tell
end filterAccountMailboxName
on logToConsole(_message)
set _logMessage to "[Poor Man's Apple Mail SaneBox] " & _message
do shell script "/usr/bin/logger -s " & _logMessage's quoted form
end logToConsole
view raw poorMansSanebox hosted with ❤ by GitHub

Activate / De-activate VPN per AppleScript

Just got a good Deal for a VPN Provider to different countries to secure Wireless Connections via VPN Unlimited.

Link to deal https://deals.cultofmac.com/?rid=199289 , offers  expires 2014/08/22

I don’t want to keep it running by default so I created a short script to activate / de-activate the VPN via Keyboard Maestro.

Keyboard Maestro Editor VPN Switch

and here the script:

tell application "System Events"
    tell current location of network preferences
        set VPNservice to service "VPN Unlimited (Germany)"
        set isConnected to connected of current configuration of VPNservice
        if isConnected then
            disconnect VPNservice
            set onOff to "off"
        else
            connect VPNservice
            set onOff to "on"
        end if
    end tell
end tell
return onOff

I now just need to figure out how to use more than one profile (the profile is auto configured via an app).

Still if this VPN Provider works to my satisfaction I guess I will subscribe longer after the first 3 years.

Can not convert \”22.5\” to number

While writing a script to get some information from top of the command line into applescript
and compare the numbers I stumbled upon a problem.
 
While top returns 22.5 applescript on my mac sees a number as 22,5.
 
The mac I use has german as locale, looks like the locale of the command line isn’t the same
and uses us notation.
 
So I created a short snippet to convert a string from 22.5 to 22,5 which can than be converted
to a number in applescript.
 
  on dotStringNumber2commaStringNumber(stringNumber)

       set resultNumber to ""
       set char_list to every character of stringNumber
       set char_list_length to count char_list
       repeat with x from char_list_length to 1 by -1
                 set current to ( item (char_list_length - x + 1) of char_list) as string
                 if current = "." then set current to ","
                 set resultNumber to resultNumber & current
       end repeat
       return resultNumber


 end dotStringNumber2commaStringNumber
 
I know this isn’t the best solution but I haven’t found a simpler one, perhapsmsomebody else knows.
 
 
 

Check if file is older than X days

Today I needed a rule in hazel which was able to check if a file was older than X days.

While there are some options in hazel like before this year, I mistrusted them to work in
the correct way and I wanted to do some more applescript.
So I wrote a quick applescript to check if the file modified date is older than X days and than
return a true.


-- Set the age of files that you want to keep
set keepDays to (360)
tell application “Finder”
set modDate to modification date of theFile
if modDate is less than ((current date)) - keepDays * days then
return true
end if
end tell
— File is younger than keepDays
return false