I am trying to write a script that will search wikipedia for a section of highlighted text. I am having two issues.
- When running the Script the 1st time it appears to work fine. However if I run it a second time it searches the previously highlighted term and the new highlighted term together which is not what I want.
ie highlight “tree” it will search tree then highlight “leg” it will search “treeleg” - Is it possible to assign a shortcut to this script if I am running it in firefox. Or maybe a option in the secondary click menu?
Any Help would be appreciated, thanks it advance.
tell application "Finder" to activate
set the clipboard to " "
tell application "Firefox" to activate
tell application "System Events"
tell process "Firefox"
tell menu bar 1
set the clipboard to " "
click menu item "Copy" of menu "Edit"
end tell
end tell
end tell
set theSelectedText to the clipboard
set searchText to " "
set searchText to theSelectedText
open location ("http://en.wikipedia.org/wiki/" & searchText)
set newText to switchText of searchText from " " to "_"
to switchText of currentText from SearchString to ReplaceString
set storedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to SearchString
set currentText to currentText's text items
set AppleScript's text item delimiters to ReplaceString
set currentText to currentText as Unicode text
set AppleScript's text item delimiters to storedDelimiters
currentText
set searchText to currentText
end switchText
property search_URL : "http://en.wikipedia.org/wiki/"
set the search_URL to (search_URL & newText)
open location search_URL
Model: MacBook Pro
AppleScript: 2.2
Browser: Firefox 2.0.0.14
Operating System: Mac OS X (10.5)