2013-06-18 53 views
1

我在Applescript中創建了一個'從列表中選擇',其中的選項是.txt文件中的行。它看起來像這樣:applescript從列表結果中選擇

set listofUrls to {} 
    set Urls to paragraphs of (read urlList) 
    repeat with nextLine in Urls 
     if length of nextLine is greater than 0 then 
      copy nextLine to the end of listofUrls 
     end if 
    end repeat 
    choose from list listofUrls with title "Refine URL list" with prompt "Please select the URLs that will comprise your corpus." with multiple selections allowed 

這個作品非常漂亮,如果我返回結果',我得到在正式的「網址X」結果窗口列表「urlb」等

的問題是看過那部當我嘗試這個列表保存到一個文本,用,例如:

write result to newList 

文件的格式是奇怪:

列表utxtÇhttp://url1.htmlutxtÇhttp://url2.htmlutxt~http://url3.htmlutxtzhttp:// ...

似乎空字符已經插入了。那麼,有人知道發生了什麼嗎?任何人都可以想辦法:

a)寫結果爲乾淨(最好是換行符)txt? b)清理這個輸出,使其恢復正常?

謝謝你的時間! 丹尼爾

+0

我可以看到你的文件寫入代碼,那是你遇到問題的地方 – mcgrailm

回答

0

沒有看到你寫的文件是什麼,我認爲你只需要結果轉換爲字符串與段落

僞代碼

set listofUrls to {} 
set urlList to ":Users:loaner:Documents:urllist.txt" as alias 
set Urls to paragraphs of (read urlList) 
repeat with nextLine in Urls 
    if length of nextLine is greater than 0 then 
     copy nextLine to the end of listofUrls 
    end if 
end repeat 
choose from list listofUrls with title "Refine URL list" with prompt "Please select the URLs that will comprise your corpus." with multiple selections allowed 

set choices to the result 
set tid to AppleScript's text item delimiters 
set AppleScript's text item delimiters to return 
set list_2_string to choices as text 
set AppleScript's text item delimiters to tid 
log list_2_string 
write list_2_string to newList 
+0

是的!我想這是文本項目分隔符的問題。這絕對是一種享受!非常感謝,朋友。 – user2437842

+0

高興地幫助:) – mcgrailm

+0

基本上你試圖寫清單到文件,它將分隔符轉換成一些奇怪的東西:) – mcgrailm