2014-08-27 23 views
1

我使用這個代碼添加到每個所選曲目在iTunes添加到AppleScript的對象 - 一個列表:setStringValue使用AppleScript列表

tell application "iTunes" 
     set these_titles to {} 
     if selection is not {} then 
      set mySelection to selection 
      repeat with aTrack in mySelection 
       if class of aTrack is file track then 
        set end of these_titles to ((name of aTrack) as string) 
       end if 
      end repeat 
     end if 
    end tell 

我有這條線顯示在文本框中輸出GUI:

trackTable's setStringValue_(these_titles) 

但它出來是這樣的:

Output of setStringValue

是否有任何方法可以讓每個列表項在一行上,無引號和括號?

回答

1

這是列表的正確輸出。如果您希望將其強制爲特定格式的字符串,則需要明確執行此操作。只需更改用於列表的分隔符,然後將該變量強制爲一個字符串,該字符串將該分隔符作爲每個列表項目之間的文本。 所以,這個代碼添加到你的代碼的末尾:

set oldTID to AppleScript's text item delimiters 
set AppleScript's text item delimiters to ", " 
set these_titles to these_titles as string 
set AppleScript's text item delimiters to oldTID 

更改到任何你想要的分隔符,以代替逗號和空格。

+0

超級!我在第一行改成了'將AppleScript的文本項目分隔符設置爲「\ n」',並且得到了我想要的。 – 2014-08-27 22:42:07

1

因爲這個話題與AppleScriptObjC有關,所以我也想展示一下。

set these_titles to these_titles's componentsJoinedByString:", "