Creating a kill switch for the OSX VPN client

I live in China so I have to use VPN all the time if I want any kind of stable connection to sites in the west. Unfortunately the VPN will at times randomly disconnect and then all traffic will immediately start going over chinese Internet again. While this is not a big deal really, I would just prefer not to be logged in to Facebook or Gmail and have my traffic open to be sniffed by the great firewall. It also occurred to me that many people use VPNs in the states in order to safely torrent.

I know some VPN providers have ‘Internet kill switches’ for their VPN that will cut your Internet connection incase of a disconnect and make sure you are not leaking anything. The problem with these is that they are almost all using openVPN, while I use L2TP over IPSec for my VPN. I searched for a long time for a way to do this and could not find one so I thought of a way to do it on my own. The following is how I set my system up. Please keep in mind that I am not an experienced Term …

Source: Mac OSX Hints

    

Automator Service to toggle the alias bit

Aliases in OS X are identified to the system by an attribute referred to as the alias bit. This hint provides a very simple way to be able to toggle the alias bit of selected files within the Finder.

There may be some need to be able to toggle the alias bit of files from within the Finder. For example, I found that using Bittorrent Sync to keep files synchronized across multiple devices is very useful and a real time saver, but suffers from a bug in the OS X version, that causes aliases to lose their status as aliases. I traced the problem to the alias bit not syncing and though the developers continue to promise to fix it, I got tired of waiting.

So I put together an Automator action that installs as a service in OS X. It adds a Service to the contextual menu that will toggle the alias bit on any file or folder in the Finder. It works on multiple files at once. Just select what you want, right click, and choose ‘Toggle Alias Bit.’ I made it a toggler rather than …

Source: Mac OSX Hints

    

Add Multiple URLs to a Calendar Event

I frequently want to add multiple URLs to Calendar events. Of course, you can put them in the Notes section, but given that there’s a URL field, it seems a little kludgey. This solution is kludgey too, but perhaps a bit less so.

Drag the additional link(s) to the Finder to create a .webloc file; then drag that file to the attachment field for the event.

You can double-click the file to open the link, which is better than the link being non-clickable in the Notes field, where you would have to highlight and right-click (Control+click). The URL won’t appear in the body of an email when you send an event to someone, but it will be in the attached .ics file.

[crarko adds: I haven’t tested this one.]

Source: Mac OSX Hints

    

Apple Announces Q214 Profit of $10.2 Billion, Revenue of $45.6 Billion

By Alex Brooks Apple’s Quarterly Earnings until Q214
Apple today announced financial results for its second fiscal quarter of 2014 which ran from January 1, 2014 until March 29. Apple posted revenue of $45.6 billion and net quarterly profit of $10.2 billion, or $11.62 per diluted share. These results compare to revenue of $43.6 billion and net profit of $9.54 billion, or $10.09 per diluted share, in the year-ago quarter.
Gross margin was 39.3 percent compared to 37.5 percent in the year-ago quarter. International sales accounted for 66 percent of the quarter’s revenue.
Apple reported the following number of shipments for its products during the quarter:
43.7 million iPhones compared to 37.4 million in the year-ago-quarter
16.35 million iPads compared to 19.5 million in the year-ago-quarter
4.1 million Macs compared to 3.95 million in the year-ago quarter
2.76 million iPods compared to 5.63 million in the year-ago quarter.

“We’re very proud of our quarterly results, especially our strong iPhone sales and record revenue from services,” said Tim Cook, Apple’s CEO. “We’re eagerly looking forward to introducing more new products and services that only Apple could bring to market.”
“We generated $13.5 billion in cash flow from operations and returned almost $21 billion in cash to shareholders through dividends and share repurchases during the March quarter,” said Peter Oppenheimer, Apple’s CFO. “That brings cumulative payments under our capital return program to $66 billion.”
Apple provided the following guidance for its fiscal 2014 third quarter:
revenue between $36 billion and $38 billion
gross margin between 37 percent and 38 percent
operating expenses between $4.4 billion and $4.5 billion
other income/(expense) of $200 million
tax rate of 26.1%

Source: World of Apple

    

Create a Fusion Drive with a Recovery Partition

There are many step-by-step guides on the internet that explain how to add an SSD to an existing Mac, and create a ‘Fusion Drive’ that has the speed of an SSD, but also the capacity of a Hard Drive. All these guides fall short in one way that was important to me.

Creating the Fusion Drive the way these walkthroughs say (including OWC’s exceptional guides), destroys the Recovery Partition that exists on the drive. Without a Recovery Partition, you cannot enable FileVault2, and will need some other external boot drive if you ever need to perform maintenance on your internal drives. For a laptop computer that might be far from home, not having a Recovery Partition was unacceptable to me. Also note that if you buy a Mac from Apple today with Fusion Drive, it DOES come with a Recovery Partition, so it is indeed possible to do.

It turns out that Apple’s Core Storage technology is more flexible than these walkthroughs give on. You can enroll an individual partition of a …

Source: Mac OSX Hints

    

Using Time Machine on unsupported volumes

I wanted to use Time Machine on my exFAT hard drive, but turns out that these volumes aren’t supported from Time Machine! There is a very simple way to use Time Machines on unsupported hard drives, as long as you follow these instructions carefully you shouldn’t have any issues at all.

First, connect the unsupported volume (in this case, an exFAT external hard drive.) When it mounts, open the Terminal and type these commands, substituting ‘My External HDD Name’ for the name of the unsupported volume.

cd /Volumes
cd ‘My External HDD Name’

Next, type this code, substituting for your needs:

hdiutil create -size 320g -type SPARSEBUNDLE -fs “HFS+J” MacBook-Backup.sparsebundle
open MacBook-Backup.sparsebundle

Here, a 320GB sparse bundle named ‘MacBook-Backup’ is being made and mounted. You can change these values as you see fit. From herein, I’ll refer to the sparse bundle name as ‘MacBook-Backup’.

Source: Mac OSX Hints

    

10.8: AppleScript to close iCal Alerts

I’d just installed OS X 10.8, and booted to find the right side of my screen covered in Birthday and Calendar notifications! Since installing I’ve clicked ‘Close’ on way too many iCal notification alerts.

Here’s a script to close them all for you in one fell swoop. Since I still want iCal to popup a Notification alert for event alarms I’ve set, I don’t want to simply disable all the iCal notifications (or set them to temporary banner alerts).

However, it still occurs that sometimes a small pile of alerts have accrued while I was away from the computer, and I really hate hitting ‘Close’ a bunch of times.

So, followng is a script to simply close all the piled-up Notification Alerts. The script was put together using these two webpages for inspiration: http://macosxautomation.com/mavericks/notifications/01A.html (most of the nice code comes from here) and …

Source: Mac OSX Hints

    

Create very unique signatures in Preview

You can make signatures in Preview that are pen and ink style drawings.

I don’t know if this has been posted yet, or if it is generally known, but I stumbled upon a neat feature of signatures in Preview.app. When you create a signature, if you you don’t hold up a piece of paper with a signature on it, and simply smile for a mug shot, Preview will create a signature that is a neat pen and ink style image of yourself, or whatever is in front of the camera. I’ve created several, that for the right client, can be used as a humorous alternative to an actual signature. I also used a screen capture of the signature on a document and made the image into a Facebook Profile picture.

[crarko adds: Well I didn’t know about it. Most folks use Photo Booth to do things like this, I’d guess, but I always appreciate a creative use of a program.]

Source: Mac OSX Hints

    

Custom margins in TextEdit

There is already an old hint about this topic, but it doesn’t really explain it very clearly, only in the comments.

Here’s how you can change the margins in TextEdit to your favourite size, so that you can use, for example, the whole space on a sheet of paper when printing.

First, save your document first as a Rich Text file (.rtf), if you have not already done this. To see the effect directly in your document, open it and enable under the Format menu the setting Wrap to Page for your document.

Next open up the TextEdit preferences, switch to the tab Open and Save and check on the option Display RTF files as RTF code instead of formatted text.

Open the document again and you will see the raw code that defines how the document look like. You want to look in the 4th row, where it says:
margl1440margr1440

This define …

Source: Mac OSX Hints

    

Automatically create Calendar events when receiving email

By Matt Swain I’m always looking for ways to automate the most repetitive tasks I find myself doing on my Mac. The other day, I realised that I spend a lot of time manually creating Calendar events by copying information from booking confirmation emails. This is exactly the sort of task that can be easily automated to save you a little bit of time and effort every day.

Here’s how you can set up a custom rule in Mail app that runs a short AppleScript to create a new event in Calendar app.

To illustrate how to do this, I’m going to use an example that I’ve set up for myself. I regularly receive booking confirmation emails from my local cinema that look like this:

All the information to create a Calendar event is there in the text, but it is annoyingly time consuming to do this manually. Let’s set up a Rule to process these emails automatically.

In Mail app, choose Preferences from the Mail menu, and click on the Rules tab. Create a new rule, and adjust the drop down menus to look like the screenshot below. The first section shows the conditions required to apply the rule to a message. In my case, I restrict the rule to only messages from “noreply@cineworldmail.com” in my “iCloud” account. When an email that meets these criteria is received, a series of actions are performed. First the message is moved out of my inbox into another mailbox, and it is marked as read.

The final action is the most complicated. It is a custom AppleScript that reads the email, figures out the name, date, time and location, then creates a Calendar event.

When you first choose Run AppleScript from the drop down menu, there will not be any AppleScripts available for you to run. First we have to create one.

To do this, open up AppleScript Editor. This is located in the Utilities folder in the Applications folder, or you can find it using Spotlight search or Launchpad. In the script window that appears, paste the following script:

— Triggered by Mail rule.
using terms from application “Mail”
on perform mail action with messages msgs for rule theRule
tell application “Mail”
repeat with msg in msgs
try
set msgcontent to content of msg
set msgid to message id of msg
set {movie, runtime, cert, bref, starttime, addr, screen} to my parseMsg(msgcontent)
my createEvent(movie, runtime, cert, bref, starttime, addr, screen, msgid)
end try
end repeat
end tell
end perform mail action with messages
end using terms from

This is the general format of all Mail rule AppleScripts. One of the benefits of AppleScript is that it is very close to normal English language, and you can get some idea of what a script does even if you aren’t familiar with AppleScript. The above script takes each email message that the rule matched, and runs a function called parseMsg on it to extract the event details. Then it runs a function called createEvent using those details.

Next, below this paste the following functions:

— Parse the email content to extract movie details.
on parseMsg(msgcontent)
set movie to extractBetween(msgcontent, “You are going to see: “, “Cert: “)
set cert to extractBetween(msgcontent, “Cert: “, “Running Time: “)
set runtime to extractBetween(msgcontent, “Running Time: “, ” minutes”)
set bref to extractBetween(msgcontent, “Booking Reference: “, “Date: “)
set datestring to extractBetween(msgcontent, “Date: “, “Cinema: “)
set addr to extractBetween(msgcontent, “Cinema: “, “Screen: “)
set screen to extractBetween(msgcontent, “Screen: “, “Number of people going: “)
set starttime to parseDateString(datestring)
return {movie, runtime, cert, bref, starttime, addr, screen}
end parseMsg

— Extract the substring from between two strings
to extractBetween(theString, startText, endText)
set tid to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to startText
set startComps to text items of theString
set AppleScript’s text item delimiters to endText
set endComps to text items of second item of startComps
set AppleScript’s text item delimiters to tid
return trim(first item of endComps)
end extractBetween

— Trim all whitespace from start and end of a string
on trim(theString)
set theChars to {” “, tab, character id 10, return, character id 0, character id 8232}
repeat until first character of theString is not in theChars
set theString to text 2 thru -1 of theString
end repeat
repeat until last character of theString is not in theChars
set theString to text 1 thru -2 of theString
end repeat
return theString
end trim

— Parse date and time from the string given in the email.
on parseDateString(datestring)
set theDate to current date
set dateWords to words of datestring
set day of theDate to text 1 thru -3 of item 2 of dateWords
set time of theDate to (item 5 of dateWords) * hours + (item 6 of dateWords) * minutes
set monthList to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with i from 1 to 12
if item 3 of dateWords = ((item i of monthList) as string) then
set monthNumber to (text -2 thru -1 of (“0” & i))
exit repeat
end if
end repeat
set month of theDate to monthNumber
return theDate
end parseDateString

This is the core of the AppleScript, which parses the email to extract the event details. The way it works is to extract the text between two other pieces of text. For example, it extracts the text between You are going to see: and Cert: and sets it as the name of the movie. You will need to modify this to match the exact format of your email. A bit of trial and error may be necessary, so you may want to test the rule on emails you send to yourself.

Finally, paste the following function that creates the Calendar event:

— Create a calendar event for the specified movie.
on createEvent(movie, runtime, cert, bref, starttime, addr, screen, msgid)
set endtime to starttime + runtime * minutes
tell application “Calendar” to tell calendar “Home”
set theEvent to make new event with properties {start date:starttime, end date:endtime, summary:”Cinema: ” & movie}
set location of theEvent to screen & “, Cineword ” & addr
set description of theEvent to “Booking Reference: ” & bref & return & “Run Time: ” & runtime & ” minutes” & return & “Certificate: ” & cert
set url of theEvent to “message://” & “%3c” & msgid & “%3e”
end tell
end createEvent

You will also need to modify this to match the exact details in your email messages. Above, I set the name of the even to the title of the movie and I calculate the end time by adding the running time of the movie to the start time. I set the location of the event to the screen number and the cinema address, and I add a few details to the event notes like my booking reference number. Setting the url of the event to the email message id also provides a handy link back to the original email message from within Calendar.

You can find the full script here.

Now all we need to do is save the AppleScript somewhere Mail can see it. Choose Save from the File menu, and then press Command-Shift-G to bring up the Go to folder dialog. In the text field, type ~/Library/Application Scripts/com.apple.mail and press Return. Give the script a memorable name and save it. Now, when you return to Mail, your script should be available in the drop down menu next to “Run AppleScript”.

Source: Mac OSX Tips