I’m trying to set the path of a folder, and then return the result of that path in a shell script. Problem is that the shell script doesn’t like the colon “:”.
I want my path to be HD/Users/myname/path/to/folder
instead of HD:Users:myname:path:to:folder
How would I go about replacing the “:” in the path with a “/”.
property ChooseFolderPrompt : "Please choose a folder"
choose folder with prompt ChooseFolderPrompt
set the message_text to the result
set the message_text to replace_chars(message_text, ":", "/")
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
set this_text to TargetFolder
end replace_chars
-- ETC.
-- ETC.
set this_data to do shell script "shell command goes here... " & " " & TargetFolder
I keep getting the error "Can’t get every text item of “HD:Users:myname:path:to:folder:”
TIA
property ChooseFolderPrompt : "Please choose a folder"
set TargetFolder to quoted form of POSIX path of (choose folder with prompt ChooseFolderPrompt)
set this_data to do shell script "shell command goes here... " & " " & TargetFolder
To escape an apostrophe, use two backslashes in your applescript…
do shell script "ls /path/to/Martin\'s\ Folder"
Note that there is a space after the last backslash before Folder and that there is no space before the apostrophe.
Or you can use the “quoted form” as JJ and Rob mentioned above.