Skip to content

Instantly share code, notes, and snippets.

Created March 27, 2012 00:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save anonymous/2211017 to your computer and use it in GitHub Desktop.
Save anonymous/2211017 to your computer and use it in GitHub Desktop.
on searchReplace(theText, SearchString, ReplaceString)
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to SearchString
set newText to text items of theText
set AppleScript's text item delimiters to ReplaceString
set newText to newText as text
set AppleScript's text item delimiters to OldDelims
return newText
end searchReplace
on run {input, parameters}
set myClip to the input
set mytext to searchReplace(myClip, "<", "")
set mytext to searchReplace(mytext, ">.", "")
set mytext to searchReplace(mytext, ">", "")
set findIt to "\\"
set replaceIt to "/"
set mylocation to searchReplace(mytext, findIt, replaceIt)
set mylocation to "smb:" & mylocation
tell application "Finder"
open location mylocation
end tell
return input
end run
@klausmartin
Copy link

Running the script Automator throws the alert "every text item can not be read".
Any ideas?

@jcontois
Copy link

I am having the same issue. "Can’t get every text item."

any update on this?

@jcontois
Copy link

@klausmartin I resolved it, somehow.

See code below:

on searchReplace(theText, SearchString, ReplaceString)
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to SearchString
set newText to text items of theText
set AppleScript's text item delimiters to ReplaceString
set newText to newText as text
set AppleScript's text item delimiters to OldDelims
return newText
end searchReplace

on run {input, parameters}

set mytext to the input
set mytext to searchReplace(mytext, "<", "")
set mytext to searchReplace(mytext, ">.", "")
set mytext to searchReplace(mytext, ">", "")
set mytext to searchReplace(mytext, " ", "%20")
set findIt to "\\"
set replaceIt to "/"
set mylocation to searchReplace(mytext, findIt, replaceIt)
set mylocation to "smb:" & mylocation

tell application "Finder"
	open location mylocation
end tell

return input

end run

@johnbiondini
Copy link

Hi,

I just tried with the latest edit but I still have the "Can’t get every text item." error. :(

Any help?
Thanks
screen shot 2018-02-13 at 15 18 08

@thetitan
Copy link

thetitan commented Mar 3, 2018

The solution to replace spaces with "%20" won't work. You could try "%%20", which should compile to "%20" in the CLI, but that approach will not work in the Mac Terminal. You should simply escape the space using the forward slash - "\ ".

Escaping special characters should always be the preferred method. But be aware, there will be situations where you would have to escape the escape character, e.g. "\\t", depending on what your script is trying to do.

Have a look at https://apple.stackexchange.com/a/144935/7066

@m7ess5
Copy link

m7ess5 commented Oct 8, 2018

using this variant is working for me:
replace
tell application "Finder"
with
tell application "System Events"

@weilinzung
Copy link

weilinzung commented Oct 31, 2018

Not support if folder has special characters :
| & : ; ( ) < > ~ * @ ? ! $ # [ ] { } \ / ' " `

Any ideas?

@lauramariez
Copy link

I've tried this code and still get the Syntax Error "can't get every text item" like the folks above; Does anyone have an updated solve for this?

@jonalange
Copy link

I've tried this code and still get the Syntax Error "can't get every text item" like the folks above; Does anyone have an updated solve for this?

So solve the error, don't run the script inside automator.
At the top (in automator) set it from "auto" (translated from german) to "Text" and test it with an actual path.
The script can't do anything inside automator because no text is selected to open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment