Archive

Archive for July, 2009

Applescript to safely open links from Apple Mail

July 27th, 2009 No comments

I’m (justifiably) nervous about following links from emails.  I wrote an applescript that sets my mind at ease.  It works like this:

  1. I copy the link to the clipboard (right-click on it)
  2. I run the script
  3. it automatically finds the site name e.g. “orbitz” from “orbitz.com” and opens up a new google search in Safari.
  4. When I click on the hit that’s the real site, the script inserts the domain name of the real site into the link from the email
  5. The valid link comes up in Safari

I just thought about searching my Safari bookmarks, but this got the process down from manually editing the URL to three mouse clicks, so I’m happy :)


set link_to_scrub to (get the clipboard)

set text item delimiters to "/"
set tokens_to_scrub to text items of link_to_scrub

set domain_name_to_scrub to (get item 3 of tokens_to_scrub)

set text item delimiters to "."
set url_labels_to_scrub to text items of domain_name_to_scrub

tell application "Safari"
activate
make new document with properties {URL:"http://www.google.com/search?q=" & (item 2 of url_labels_to_scrub)}

set current_url to a reference to URL of document 1

repeat until current_url starts with "http://www.google.com/"
delay 0.1
end repeat

repeat while current_url starts with "http://www.google.com/"
delay 0.1
end repeat
end tell

set text item delimiters to "/"
set real_tokens to text items of (current_url as string)

set real_domain_name to (get item 3 of real_tokens)

set text item delimiters to "."
set real_url_labels to text items of real_domain_name

repeat with current_label_index from -2 to -1
set item current_label_index of url_labels_to_scrub to item current_label_index of real_url_labels
end repeat

set real_domain_name to url_labels_to_scrub as string
set item 3 of tokens_to_scrub to real_domain_name

set text item delimiters to "/"
set real_link to (tokens_to_scrub as string)

tell application "Safari"
activate
set URL of document 1 to real_link
end tell

Categories: Applescript, Mac Tags: , , ,

Applescript Studio Debugger/Breakpoint Fiasco

July 16th, 2009 No comments

I was working on an Applescript Studio project with Objective-C mixed in, when all of a sudden, without any warning or intervention from me, the debugger ceased to load when I ran the app (in debug mode). Hmmm, little gremlins, hackers from Russia???

After searching the lists and checking off the usual culprits (debug configuration, yes; debug symbols enabled, ditto), I went to my old-standby-last-resort-when-xcode-starts-acting-crazy-for-no-reason move: I created a fresh project, confirmed that it was working normally, and then opened every setting window in both projects to see what settings are different, and so could possible be contributing to the hiccup.

When I opened the settings for the executable (I was desparate), I noticed that the “Debugging->When using…” drop-down was different. Now, to you or I, “when using” seems to say “these setting only apply when you happen to be using X.” Yet on planet Xcode, it seems to translate into “when you change X, you’re project will begin to work in a different way then usual, even if you do not change any o the settings in this window.” I selected “GDB” from the drop-down, and all my problems were solved… maybe that’s a bit dramatic.

Anyway, my breakpoints are again working (in both the Obj-C and applescript code). Yay!

Categories: Mac, Programming, Xcode Tags: , ,

Getting the process ID of a Mac App

July 15th, 2009 No comments

It seems like a common-enough problem, yet after striking out on the mailing list archives, coding sites, and Apple Developer Connection, I wrote this little Cocoa snippet to find the process ID of a particular app:

// Just replace this first string with your app name
NSString* target_app_name = @"Finder";
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSArray* active_apps = [workspace launchedApplications];
NSNumber* process_id = nil;

for (int i = 0; i < [active_apps count]; ++i) {
  NSDictionary* current_app = [active_apps objectAtIndex:i];
  NSString* app_name = [current_app valueForKey:@"NSApplicationName"];

  if ([app_name isEqualToString:target_app_name])
  process_id = [current_app valueForKey:@"NSApplicationProcessIdentifier"];
}
Categories: Mac, Programming Tags: ,

windows 7 product key

windows 7 product key

windows 7 key generator

windows 7 key generator

free winrar download

free winrar download

winzip activation code

winzip activation code

free winrar

free winrar

winzip free download

winzip free download

winrar free download

winrar free download

winrar download free

winrar download free

winzip free download full version

winzip free download full version

windows 7 activation crack

windows7 activation crack

windows 7 crack

windows 7 crack

free winzip

free winzip
\n