• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Find and replace space by the Terminal equivalent
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Find and replace space by the Terminal equivalent


  • Subject: Re: Find and replace space by the Terminal equivalent
  • From: Barry Wainwright <email@hidden>
  • Date: Sun, 02 Oct 2005 08:39:03 -0700
  • Thread-topic: Find and replace space by the Terminal equivalent

On 2/10/05 08:02, "Jay Louvion" <email@hidden> wrote:

> le 2/10/05 14:20, Mark J. Reed à email@hidden est réputé(e) avoir
> écrit :
>
>> "\ " isn't a legal AppleScript string literal. You need to double the \.  "\\
>> ".
>>
>
> I understood things until there. Unfortunately, the wanted result isn¹t
> possible then ?
>
> This is what I¹ve got for the moment:
>
> set Target to ³/Users/ptilu/Desktop/Copy Stuff/²
> set Target to (FindReplace(" ", "/\\ ", Target))
> on FindReplace(FindWhat, ReplaceBy, ThisString)
>     copy the text item delimiters to OldDelims
>     set the text item delimiters to {FindWhat}
>     set tempList to every text item of ThisString
>     set the text item delimiters to {ReplaceBy}
>     set newString to tempList as text
>     set the text item delimiters to OldDelims
>     return newString
> end FindReplace
>
> But the output is not ³do shell² compatible: /Users/ptilu/Desktop/Copy/\\
> Stuff/
>
> Full script as attachment. Using osxutils.
>

Your script contains these lines:

if answer is "File" then
    set Target to POSIX path of (choose file default location (path to home
folder as alias) without invisibles) as text
else
    set Target to quoted form of POSIX path of (choose folder) as text
end if
set Target to (FindReplace(" ", "/\\ ", Target))
return "seticon " & IconSource & " " & Target --for testing in SE
--do shell "seticon " & IconSource & " " & Target


If the user has chosen 'file' then you return the 'quoted form of' the path.
You don't is the user chose 'folder'.

If you use the 'quoted form of' construct for both cases, there is no need
to replace any of the spaces, quoting a path with spaces will protect it
from the shell, so, this should work OK:

if answer is "File" then
    set Target to quoted form of (POSIX path of (choose file default
location (path to home folder as alias) without invisibles) as text)
else
    set Target to quoted form of (POSIX path of (choose folder) as text)
end if
return "seticon " & IconSource & " " & Target --for testing in SE
--do shell "seticon " & IconSource & " " & Target
(note that the entire find/replace routine is redundant)


Note that you are probably being confused by how SE is displaying the result
- SE will display an applescript-ready form of the string, so escapeable
characters will be displayed as escaped, even though they wouldn't be
double-escaped when the script runs. SE displays a result that can be
copy/pasted into a script so as to give the correct result within the
scritp, this means the human form of the display does not always match what
the machine will see, I know I've explained this badly, but I don't know how
to say it better!

--
Barry



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Find and replace space by the Terminal equivalent
      • From: Jay Louvion <email@hidden>
References: 
 >Re: Find and replace space by the Terminal equivalent (From: Jay Louvion <email@hidden>)

  • Prev by Date: Re: iCal and Applescript (beginner)
  • Next by Date: Re: Problems saving applet with custom icon--icon gets stripped by PackageMaker
  • Previous by thread: Re: Find and replace space by the Terminal equivalent
  • Next by thread: Re: Find and replace space by the Terminal equivalent
  • Index(es):
    • Date
    • Thread