Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

benlafleche

macrumors newbie
Original poster
Mar 18, 2011
1
0
Hello,

I trying to make TextWrangler create a project from the files that are opened in a window. I found the code below to create a text file listing all the documents (file path included) that were open a window of TextWrangler. The second script enables TextWrangler to open the list of files.

The problem is that all spaces in file paths are replaced by %20 since the code is getting URL's.
Example:
file://localhost/Users/benlafleche/g%20/TextWrangler%20Docs.txt
instead of
file://localhost/Users/benlafleche/g y/TextWrangler Docs.txt

I do program in other languages but applescript is new for me. Can anyone help me with this please. :confused:

Script found on:
Code:
http://hints.macworld.com/article.php?story=20071024121225545

To save the list of files :
Code:
tell application "TextWrangler"
  set alldocs to every text document of text window 1
  set allfiles to {}
  set str to ""
  repeat with adoc in alldocs
    if is FTP of adoc then
      set ftpinfo to FTP Info of adoc
      set murl to URL of ftpinfo
    else
      set murl to URL of adoc
    end if
    set end of allfiles to murl
    set str to str & "||" & murl
  end repeat
  set filename to (choose file name default name "TextWrangler Docs.txt")
  
  set saver to make new text document
  open saver opening in new_window
  set text of saver to "--docsaver do not edit this line" & str
  save saver to filename
  close saver
end tell

To open the files listed:
Code:
tell application "TextWrangler"
  set filename to (choose file)
  open filename opening in new_window
  set allfilesstr to text of text document 1
  close text document 1
  set allfiles to rest of my splitit(allfilesstr, "||")
  set hasFTP to false
  
  repeat with afile in allfiles
    if afile contains "ftp" then
      set hasFTP to true
    end if
  end repeat
  set ps to ""
  if hasFTP then
    set ps to text returned of (display dialog "Type your password of the server your files are on" default answer "")
  end if
  if length of allfiles is greater than 0 then
    set afile to item 1 of allfiles
    set afile to my snr(afile, ":@", (":" & ps & "@"))
    open location afile
  end if
  set allfiles to rest of allfiles
  repeat with afile in allfiles
    set afile to my snr(afile, ":@", (":" & ps & "@"))
    open location afile
  end repeat
end tell

on snr(the_string, search_string, replace_string)
  tell (a reference to my text item delimiters)
    set {old_tid, contents} to {contents, search_string}
    set {the_string, contents} to {the_string's text items, replace_string}
    set {the_string, contents} to {the_string as Unicode text, old_tid}
  end tell
  return the_string
end snr

on splitit(the_string, search_string)
  tell (a reference to my text item delimiters)
    set {old_tid, contents} to {contents, search_string}
    set {arr, contents} to {the_string's text items, old_tid}
  end tell
  return arr
end splitit
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.