Skip to content

Instantly share code, notes, and snippets.

/gist:2211017
Created Mar 27, 2012

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

klausmartin commented Oct 20, 2017

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

@jcontois

This comment has been minimized.

Copy link

jcontois commented Jan 29, 2018

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

any update on this?

@jcontois

This comment has been minimized.

Copy link

jcontois commented Jan 29, 2018

@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

This comment has been minimized.

Copy link

johnbiondini commented Feb 13, 2018

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

This comment has been minimized.

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

@maustyle

This comment has been minimized.

Copy link

maustyle commented Oct 8, 2018

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

@weilinzung

This comment has been minimized.

Copy link

weilinzung commented Oct 31, 2018

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

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.