#This script searches Computerworld.com for the contents of text in the clipboard.
set url1 to "http://www.computerworld.com/action/googleSearch.do?cx=014839440456418836424%3A-khvkt1lc-e&q="
set url2 to "&x=0&y=0&cof=FORID%3A9#1214"
tell application "System Events"
set myquery to the clipboard
end tell
-- changes space to plus using function at end of file
set thequery to SaR(myquery, " ", "+")
tell application "Safari"
activate
tell application "System Events"
tell process "Safari"
click menu item "New Tab" of menu "File" of menu bar 1
end tell
end tell
set theURL to url1 & thequery & url2
set URL of document 1 to theURL
end tell
-- handler (function) for search and replace
-- (posted by James Nierodzik at macscripter.net)
on SaR(sourceText, findText, replaceText)
set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, findText}
set tempText to text items of sourceText
set AppleScript's text item delimiters to replaceText
set sourceText to tempText as string
set AppleScript's text item delimiters to atid
return sourceText
end SaR
The good news here is that you can get some decent support for regular expressions by installing a free add-on from Satimage or, for smaller amounts of text, dumping it into an app like TextWrangler, which has such support. AppleScript can also incorporate more powerful commands from Perl, Ruby, Unix or anything else that can be accessed via a shell script, and then assign the results to a variable. For more on that, check out Apple's technical note called "do shell script in AppleScript."
Despite its drawbacks -- and what language doesn't have any? -- I've found AppleScript to be a great tool for parsing drudgework out of my workday.
And now, without further ado, here's a sampling of cool AppleScripts out there that just might make you love your Mac even more.
Search for any term in your clipboard on Computerworld or elsewhere
This is one of my faves: Take any term you've copied into your clipboard (command-C), regardless of the app you're in, and Safari displays search results on that term from Computerworld.com.
To use:
- Copy the code.
- Open your script editor (you'll find it in your Applications/AppleScript folder).
- Paste the code into the larger top portion of your script editor.
- Save the file as a script in your Library/Scripts folder. (Note: If you open the AppleScript utility in the Applications/AppleScript folder, you can have your script menu display in the top menu bar.)
Code
If you want scripts that will search for terms in your clipboard at other sites, MacScripter has AppleScript versions posted for searching highlighted text on Google and Wikipedia (within Safari only). Download and install in your Scripts folder.
Getting the most out of AppleScript
- Google I/O 2013's Coolest Products and Services
- 10 Star Trek Technologies That are Almost Here
- 19 Generations of Computer Programmers
- 25 Must-Have Technologies for SMBs
- A walking tour: 33 questions to ask about your company's security
- 15 social media scams
- The 7 elements of a successful security awareness program
- IT Certification Study Tips
- Register for this Computerworld Insider Study Tip guide and gain access to hundreds of premium content articles, cheat sheets, product reviews and more.
- Software Asset Management: Ensuring Today's Assets Today's trends like BYOD and SaaS are new and exciting in terms of how they will help make our jobs more productive but...
- Software Asset Management: Getting Started Find out what steps to take that can lead your organization down the smooth path to SAM deployment.
- Gartner Report: How to Decide Whether SaaS ITSSM Tools Make Sense for Your Organization SaaS-based IT ITSSM tools appear to provide cost savings. However, failure to account for the resources to implement, integrate, operate and maintain the...
- Case Study: Hospital Turns to Email Archiving Solution to Ensure Regulatory Compliances Read this case study to learn how a cloud-based email archiving solution enabled the hospital to meet government mandates and helps avoid thousands...
- The ServiceNow Service Automation Platform During this webinar, you will discover how ServiceNow is enabling organizations to increase their competitive agility, user satisfaction and productivity, all while enhancing...
- Building a Business Case for Service Management & Automation As an IT infrastructure and operations (I&O) leader you understand the business and IT impact of service management and automation (SMA). All Operating Systems White Papers | Webcasts