2014-08-27 60 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:", "