The way URL opening in Mac OS X is actually more complicated than you would think. When you click a URL, Mac OS X does not just pass the browser the URL to open; instead, it sends it an Apple Event, with the ID kAEGetURL
, containing the URL.
I never really used Automator (it's just way too slow and limited for my typical use), so I'm not sure about this, but I doubt it has the ability to handle Apple Events. Therefore you won't be able to use Automator to achieve what you want.
You'll therefore have to resort to a normal Objective-C app in Xcode.
The two basic things you need to do are:
register your app for receiving the kAEGetURL event, and set the CFBundleURLTypes
in your app's Info.plist to include http
and https
.
Implement a method handling the kAEGetURL event, and make it copy the URL to the clipboard.
These two things are relatively straightforward to do in Objective-C; to illustrate, I've created a sample application that does this. You can view it at https://github.com/houbysoft/short/tree/master/Copy%20URL%20to%20Clipboard. The most important file is https://github.com/houbysoft/short/blob/master/Copy%20URL%20to%20Clipboard/Copy%20URL%20to%20Clipboard/AppDelegate.m, there you can see how to register for the event (this is done in the applicationWillFinishLaunching: method) and how to copy it to the clipboard (this is done in the getUrl:withReplyEvent: method).
If you're feeling lazy and just want to see that this works, grab this file, extract the application from it, set that as the default web browser (open Safari Preferences, and browse for that app in the Default web browser field). Then click on your link in Skype, and it should be copied straight to your clipboard.
Select the service template, change the input type to files, add a Run Shell Script action, select pass input as arguments, and paste this script:
pass() {
osascript - "$1" <<END
on run args
tell app (path to frontmost application as text)
text returned of (display dialog ("Enter password for " & item 1 of args) default answer "")
end
end
END
[ $? != 0 ] && exit 0
}
for f in "$@"; do
if [[ "$f" == *.enc ]]; then
pass "$f" | openssl enc -d -aes-256-cbc -pass stdin -in "$f" -out "${f%.enc}"
else
pass "$f.enc" | openssl enc -aes-256-cbc -salt -pass stdin -in "$f" -out "$f.enc"
fi
done
exit 0
It doesn't show specific error messages, you have to run the service again if you enter a wrong password, and there is no way to use the same password for multiple files. It would be easier to just do it from a shell.
Best Answer
You can use the Automator action Extract URLs from Text.