Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Extract names and emails from a text file UNIX
I have a recurring need to extract full names and email addresses from a plaintext archive of email messages. The archive is created by selecting a bunch of emails in Mail, copying them, pasting into TextEdit, and converting to plain text.

For each message in the file, the first line contains the information I wanted:
From: Joe Example <joe@example.com>
I wanted one email address per line, suitable for pasting into another location. I am far from an expert with the bash shell, but here's what I came up with—I imagine there are many more efficient ways to do this, as I'm sure experienced perl, sed, awk, etc. users may point out. Note that this is highly dependent on the format created by Apple's Mail app in OS X 10.8.

grep 'From:' /path/to/archive.txt | cut -f2 -d\< | cut -f1 -d\> | pbcopy

The grep bit pulls out the entire From: line, then the first cut command grabs the email address and the trailing close-bracket, by setting the delimiter to an open bracket. The second cut eliminates the closing bracket, by setting that as the delimiter. The output will be one email address per line, sitting on your clipboard ready for pasting. (To debug, just remove the | pbcopy bit to see the output.)

I also wanted to extract the names, and came up with a variant to do just that:

grep 'From:' ~/Desktop/testfile.txt | sed -e 's/: /:^/g' | sed -e 's/ \</^\</g' | cut -f2 -d^ | pbcopy

This one is messier, as names can contain one or more spaces. After getting the From: line, sed is used (twice) to add a carat delimiter immediately after From:, and immediately before the opening bracket of the email address. I then used cut, with the delimiter changed to the carat, to extract the full name (field two) from the found lines. Again, the results are copied to the clipboard; leave this bit off for debugging.

With the names and addresses extracted, it's fairly easy to do other stuff with them. In my case, I'm reading them into a couple of array variables in a bash script, so I can then output a name and email address pair to consecutive locations on my multi-pasteboard. If you want to use the names in an array in a bash script, you'll want to change the array delimiter from a space to a newline:

IFS='
'

Without this, your array will get split anywhere there's a space in the name values ... or so I've heard, not that it's ever happened to me!
  Post a comment  •  Comments (12)  
  • Currently 3.20 / 5
  You rated: 4 / 5 (10 votes cast)
 
[7,091 views] Email Article To a Friend View Printable Version
Set iPhone to flash LED for alerts iOS devices
A recent post on The Mac Observer pointed out a useful way to set alerts on an iPhone. If you dig deep into the ACcessibility settings (Settings > General > Accessibility), in the Hearing section, you'll find an option called LED Flash for Alerts. If you turn this on, you'll get a flash whenever you get an alert, such as for phone calls, text messages, etc. This is most useful if you're in a situation where you need to turn the sound off on your iPhone, or if you're in a noisy environment, and may not hear any alert sounds.

[kirkmc adds: This only works if the iPhone is asleep; in other words, if the screen has gone dark. It would be helpful if it flashed in all cases. Also, if you have the iPhone on a table with the LED on the bottom, you may not see the flash.]
  Post a comment  •  Comments (5)  
  • Currently 3.63 / 5
  You rated: 1 / 5 (19 votes cast)
 
[6,451 views] Email Article To a Friend View Printable Version
Change screensaver slide duration System 10.8
I like to use images of various quotes as my screensaver, but the default 3-second duration for each slide isn't enough for several of the quotes. After discovering that Apple, amazingly, no longer provides a built-in way to alter the duration of each slide, I set out to figure out how to change it to suit my preference. It works, but it's a bit of a pain, so if anyone knows of an easier method, please contribute.

I found the method on this page from CNET, the author of which apparently found it here. In 10.8, no matter how I tried altering the permissions of the relevant file and folder in the Finder or "unlocking" the file (as XCode refers to it), I could not get XCode (or TextWrangler) to write to the file, so I had to alter the CNET instructions a bit. (Side rant: I feel justified in refusing to resort to the terminal for a simple permissions change, a capability that has supposedly existed in the Finder for 9 major iterations of OS X.) Do the following:

  1. Navigate to this folder in the Finder and find the file called "EffectDescriptions.plist":
    /System/Library/PrivateFrameworks/Slideshows.framework/Versions/A/Resources/Content/
  2. Option-drag the file to create a duplicate copy and rename it "EffectDescriptions.original.plist" (just in case). Authenticate when asked.
  3. Drag "EffectDescriptions.plist" to the desktop (it will copy).
  4. Open the desktop copy in XCode, TextWrangler, or your preferred text editor.
  5. Hit Command-F to search for the entry called "JustASlide" (this works in XCode and TextWrangler).
  6. Find the sub-entry called "mainDuration." Change its numerical value from 3 to whatever value you prefer (in seconds).
  7. Save the file, close it, and drag it back into the folder you copied it from. It will ask you to authenticate, and then whether to replace the file. Do both. (You did do step 2, right?)
  8. In Terminal, type:
    sudo chown root /System/Library/PrivateFrameworks/Slideshows.framework/Versions/A/Resources/Content/EffectDescriptions.plist
    This will set the permissions of the file as they were before.
  9. Go to System Preferences and confirm with a slideshow preview that your change was effective.

As I said earlier, this is an ugly way to accomplish what should be a very simple preference setting, so if anyone knows of a more elegant solution, please share. I toyed with the idea of having a separate screensaver file in my own Library folder, but I wasn't able to determine whether that would work. Given that we're altering this setting in a private framework, it seems to me that it wouldn't.

  Post a comment  •  Comments (4)  
  • Currently 2.40 / 5
  You rated: 1 / 5 (10 votes cast)
 
[7,431 views] Email Article To a Friend View Printable Version
Added features when using Stocks app in landscape mode iOS devices
In iOS 3.0, Apple introduced landscape view for the Stocks app. At that time, it still only allowed date ranges of 1d, 1w, 1m, 3m, 6m, 1y, and 2y.
read more (94 words)   Post a comment  •  Comments (3)  
  • Currently 3.07 / 5
  You rated: 1 / 5 (14 votes cast)
 
[3,563 views] Email Article To a Friend View Printable Version
Install Windows 7 on external drive using Boot Camp (Lion) Install
Having purchased a Segate GoFlex Desktop Thunderbolt Adapter made me wonder if it's possible to install a Bootcamp-Partition on an external Drive. Well it works; sort of.
  1. Launch Boot Camp Assistant.
  2. Select the local Drive for installation (not the external Drive) it will take about 20 GB of disk space.
  3. Boot Camp Assistant will now repartition your local drive.
  4. Wait a while for Boot Camp Assistant to finish preparing the drive.
  5. When the Windows 7 Installer comes up simply choose the external drive as target, not the local one.
  6. Proceed with the installation.
When booting your Mac (holding the Option key) you'll now see that there is a local Windows 7 boot volume. Unfortunately, you will have wasted 20 GB creating a partition on your main drive.

[kirkmc adds: I haven't tested this. I don't know if Disk Utility can delete that partition; live partitioning is possible, but in some cases certain partitions can't be deleted.]
  Post a comment  •  Comments (10)  
  • Currently 2.80 / 5
  You rated: 5 / 5 (10 votes cast)
 
[46,797 views] Email Article To a Friend View Printable Version
Remove Genius mixes from iTunes Apps
I spotted something today in iTunes 11, which I don't recall seeing before. If you right-click on a Genius Mix icon, you can choose Remove > Genius Mix name> and delete it from the Genius Mixes list. If you want to get all your Genius Mixes back, you can right-click anywhere in the white space of that window and choose Restore All Mixes to get them all back. But you still have no control over how Genius Mixes are created.
  Post a comment  •  Comments (0)  
  • Currently 2.89 / 5
  You rated: 4 / 5 (9 votes cast)
 
[4,828 views] Email Article To a Friend View Printable Version
Schedule "Do Not Disturb" for Notification Center System 10.8
If you like Notification Center, in Mountain Lion, you may also like its "Do Not Disturb," feature, where you can turn off notifications if you're busy and they get to be a bother. There are a couple of ways you can do this: you can Option-click the Notification Center menu bar icon, or you can scroll down when Notification Center is visible, and toggle the slider to OFF.

On iOS, you can schedule this action, but not on OS X. Ben Waldie, writing at TUAW, posted an interesting AppleScript/Automator solution to this. You can create an Automator workflow, and set it to run in Calendar, so you can have the Do Not Disturb feature turned on and off at specific times. It's a bit ham-fisted, to be sure; it uses a defaults write or defaults delete command, then a killall NotificationCenter command, which is essentially force-quitting Notification Center and allowing it to relaunch. The problem is that if anything goes amiss, Notification Center might not relaunch.

It's too bad that there's no built-in way to do this. But this is a good solution for now, if you really want to turn Notification Center off and on at specific times.
  Post a comment  •  Comments (1)  
  • Currently 2.50 / 5
  You rated: 4 / 5 (6 votes cast)
 
[5,332 views] Email Article To a Friend View Printable Version
Create playlists in iTunes for all complete albums Apps
User Aphex5 posted an interesting question on Stack Exchange, asking if there was a way to create playlists for all complete albums in his iTunes library. He then followed up with an answer, the following AppleScript:
-- Creates a playlist for each full album you have in iTunes
-- Set the playlistPrefix and playlistSuffix as desired before running

-- Based on code by Brad Campbell
-- http://www.bradcampbell.com/2009/05/26/make-a-whole-album-playlist-in-itunes/

tell application "iTunes"
    set playlistPrefix to "FA: "
    set playlistSuffix to ""
    -- The "FA: " prefix will help cluster full albums in iTunes' playlists,
    -- and is narrow enough to not get in your way when viewing on an iPhone

    set albumBuckets to {} as list
    set allSongs to (every track of library playlist 1 whose enabled is true and podcast is false and kind contains "audio") as list

    -- Find all partial albums in iTunes
    repeat with currentTrack in allSongs
        set albumName to album of currentTrack as text
        set artistName to artist of currentTrack as text

        -- First check for missing values, then perform integer comparison
        -- Zero is on the left to force interger type coercion, just in case
        if album of currentTrack is not missing value and 0 is less than length of albumName then
            if artist of currentTrack is not missing value and 0 is less than length of artistName then
                if track number of currentTrack is not missing value and 0 is less than track number of currentTrack then
                    if track count of currentTrack is not missing value and 0 is less than track count of currentTrack then
                        if albumBuckets does not contain album of currentTrack then
                            copy album of currentTrack to the end of albumBuckets
                        end if
                    end if
                end if
            end if
        end if

    end repeat

    repeat with currentAlbum in albumBuckets
        set albumSongs to (every track of library playlist 1 whose album is currentAlbum)
        set firstTrack to first item of albumSongs

        -- Filter album list to act only on full albums
        if (count of albumSongs) is equal to track count of first item of albumSongs and 1 is less than (count of albumSongs) then
            -- This is a full album, construct the playlist

            -- Sort tracks by track number
            set albumSongsSorted to {} as list
            repeat with i from 1 to (count of albumSongs)
                repeat with trk in albumSongs
                    if track number of trk is i then
                        set nextSong to trk
                        copy nextSong to the end of albumSongsSorted
                    end if
                end repeat
            end repeat

            -- Don't show artist name for compilations
            if firstTrack is not compilation then
                set playlistNameArtist to artist of firstTrack & " - "
            else
                set playlistNameArtist to ""
            end if

            set albumPlaylistName to playlistPrefix & playlistNameArtist & currentAlbum & playlistSuffix

            -- Create playlist
            if user playlist albumPlaylistName exists then
                try
                    delete tracks of user playlist albumPlaylistName
                end try
            else
                make new user playlist with properties {name:albumPlaylistName}
            end if

            try
                repeat with trk in albumSongsSorted
                    duplicate trk to user playlist albumPlaylistName
                end repeat
            end try
        end if
    end repeat

    display dialog "Playlists created! Check iTunes for playlists beginning with '" & playlistPrefix & "'"
end tell
This will traverse the iTunes library and make playlists for every album where the number of tracks matches the total number of tracks for the album; in other words, if you only have one or six songs from a ten-song album, it won't make a playlist. Naturally, this assumes that you have the correct metadata for your tracks to enable this. If you don't, you can go through your albums - one by one, alas - using Doug Adams' Albumize Selection AppleScript; this script sets both track number and track count tags to the appropriate numbers.
  Post a comment  •  Comments (5)  
  • Currently 3.13 / 5
  You rated: 4 / 5 (8 votes cast)
 
[5,649 views] Email Article To a Friend View Printable Version
Have Spotlight results show Dictionary words just below Top Hit (or anywhere you want) System
If you use Spotlight to look up Dictionary definitions, you may find it annoying that they show up near the bottom of the list. While you can change the order of most Spotlight categories from the Search Results tab of the Spotlight pane in System Preferences, Dictionary isn't in that list.

However, there is a hack, involving some simple editing of the ~/Library/Preferences/com.apple.spotlight.plist file. A recent post on Stack Exchange explains what to do. You open the file with Xcode, then add a Dictionary item, which will allow you to move the Dictionary category to where you want in the Spotlight results. See the post linked above for full details, or see this blog post in Chinese explaining the procedure.
  Post a comment  •  Comments (3)  
  • Currently 2.63 / 5
  You rated: 2 / 5 (8 votes cast)
 
[5,590 views] Email Article To a Friend View Printable Version
Create default printer presets for multiple users Printers
I was tasked with setting up a company's new printers and had to struggle with creating a default set presets that also used a PIN number login for accounting. This needed to be pushed out to the current user base, in real time, and without interrupting anyone's ability to print. Here's how I did it.

Tools:

  • CUPS server web interface to set the printer defaults
  • ARD to install the drivers
  • lpadmin to add the printer (We're using LPD on a Windows 2008 R2 server)
  • ARD to copy the cups PPDs

1. Create the default settings:

In Terminal, run this command: sudo cupsctl WebInterface=yes
In a web browser, go to: http://localhost:631/admin

2. Install the drivers (.pkg files via ARD)

3. Add the printer using lpadmin:

lpadmin -p SweetNewPrinter-7535-clr -L "Department" -E -v lpd://WindowsServer/SweetNewPrinter-7535-clr -P /Library/Printers/PPDs/Contents/Resources/Xerox\ WC\ 7535.gz -o printer-is-shared=false

4. Copy the default cups PPDs via ARD (set permissions to: root:_lp):

/private/etc/cups/ppd/"SweetNewPrinter.ppd"

It took about an hour to set this up for 200 end users, with no scripting required.

  Post a comment  •  Comments (9)  
  • Currently 3.25 / 5
  You rated: 4 / 5 (4 votes cast)
 
[7,900 views] Email Article To a Friend View Printable Version