2010-05-17 28 views
1

我正在尝试编写一个苹果脚本,其中YY是一个两位数的数字,它将“S0XEYY”顺序地命名为我的电视节目。我有以下几点:在苹果中设置变量的宽度

tell application "iTunes" 
    set p to selection 
      set c to count of p's items 
      set fixed indexing to true 
     repeat with i from 1 to c 
      set t to item i of p 
      try 
       set the episode number of t to i 
       set the episode ID of t to "S" & (text returned of a) & "E" & i 
       set the season number of t to text returned of a 
      end try 
     end repeat 

不过,我需要的

(文本返回的)

以及

的宽度为2,填充0。我该如何去做这件事?

回答

1

这是我如何去一下吧:

if i ≤ 9 then 
    set the episode ID of t to episode ID of t & "0" & i 
else 
    set the episode ID of t to episode ID of t & i 

我确信是不是做的最好的方法,因为它假定没有更多的则需要2个字符,但它的最好的解决方案我有,这适用于这个应用程序,因为电视季节从来没有(我见过)超过20-30集。