2012-04-07 41 views
0
文件作爲CSV

更新發現的解決方案後的見底,如果有興趣看起來很簡單,併爲廣大它的工作列表,但在某些時候它攪亂皇家的。列表的數據來自InDesign中的資產,但這是我的最終結果,可以替代AS中定義的列表測試。試圖採取列表,並將其寫入使用AppleScript

tell application "Adobe InDesign CS5.5" 
set myagents to (name of properties of every asset of library "Agents.indl" as list) 
end tell 

set agentlist to "" 
repeat with currentagent in myagents 
set agentlist to agentlist & currentagent & "," 
end repeat 

set x to count agentlist 
set agentlist to characters 1 thru (x - 1) of agentlist as string 
my write_agents(agentlist) 


on write_agents(this_list) 
set the agent_log to ("/Volumes/Agents/agents.txt" as POSIX file) 
try 
    set eof of agent_log to 0 
    open for access file the agent_log with write permission 
    write (this_list) to file the agent_log starting at eof 

    --set read_data to (read the_file as list) as text 
    close access file the agent_log 
on error 
    try 
     close access file the agent_log 
    end try 
end try 
end write_agents 

取而代之的是排版的告訴頂部進行測試,我們可以使用,結果是一樣的

set myagents to {"Lois Chase Johnson", "Tammy Newton", "Team Schmidt", "Tanya Kerr", "Terry Peterson", "Brenda Clark", "Deb Kahle", "Carol Dana", "Sheryl Burley & Cathy Reed", "Linda Ulin", "Dianna Erickson", "Dave Sharman", "Lori Tracey & Chuck Murphy", "Carolyn & Robert Dodds", "Jean Ryker", "Bryan Diehl", "Lois Scheck", "Nancy Rathke", "Patrick French", "Laura Halady", "Jennifer Felton", "Clarice Arakawa", "Holly Coburn", "Quint Boe", "Michaelle Barnard", "Paul Beck", "Kelly Johnson", "Doc Reiss", "Helga Filler", "Harriet Reyenga", "Thelma Durham", "Brooke Nelson", "Dick Pilling", "David Ramey", "Rebecca Jackson", "Tim Riley", "Pili Meyer", "Marc Thomsen", "Kathy Brown", "Jean Irvine", "Kathy Love", "Kimi Robertson", "Ed Sumpter", "Jo Cummins", "Kim Bower", "Mike Fuller", "Cathy Reed", "Joyce Underwood", "Daphne Eshom", "Kathy Brown", "Dave Ramey", "Mark DeRousie", "Tom Blore", "Paul Beck", "Kelly Johnson", "Alan Burwell", "Sheryl Burley", "Vivian Landvik", "Mark HcHugh", "Jim Newton", "Chuck Turner"} 

什麼是文本文件?

Lois Chase Johnson,Tammy Newton,Team Schmidt,Tanya Kerr,Terry Peterson,Brenda Clark,Deb Kahle,Carol Dana,Sheryl Burley & Cathy Reed,Linda Ulin,Dianna Erickson,Dave Sharman,Lori Tracey & Chuck Murphy,Carolyn & Robert Dodds,Jean Ryker,Bryan Diehl,Lois Scheck,Nancy Rathke,Patrick French,Laura Halady,Jennifer Felton,Clarice Arakawa,Holly Coburn,Quint Boe,Michaelle Barnard,Paul Beck,Kelly Johnson,Doc Reiss,Helga Filler,Harriet Reyenga,Thelma Durham,Brooke Nelson,Dick Pilling,David Ramey,Rebecca Jackson,Tim Riley,Pili Meyer,Marc Thomsen,Kathy Brown,Jean Irvine,Kathy Love,Kimi Robertson,Ed Sumpter,Jo Cummins,Kim Bower,Mike Fuller,Cathy Reed,Joyce Underwood,Daphne Eshom,Kathy Brown,Dave Ramey,Mark DeRousie,Tom Blore,Paul Beck,Kelly Johnson,Alan Burwell,Sheryl Burley,Vivian Landvik,Mark HcHugh,Jim Newton,Chuck Turner �C�o�b�u�r�nutxt����Q�u�i�n�t� �B�o�eutxt���"�M�i�c�h�a�e�l�l�e� �B�a�r�n�a�r�dutxt����P�a�u�l� �B�e�c�kutxt����K�e�l�l�y� �J�o�h�n�s�o�nutxt����D�o�c� �R�e�i�s�sutxt����H�e�l�g�a� �F�i�l�l�e�rutxt����H�a�r�r�i�e�t� �R�e�y�e�n�g�autxt����T�h�e�l�m�a� �D�u�r�h�a�mutxt����B�r�o�o�k�e� �N�e�l�s�o�nutxt����D�i�c�k� �P�i�l�l�i�n�gutxt����D�a�v�i�d� �R�a�m�e�yutxt����R�e�b�e�c�c�a� �J�a�c�k�s�o�nutxt����T�i�m� �R�i�l�e�yutxt����P�i�l�i� �M�e�y�e�rutxt����M�a�r�c� �T�h�o�m�s�e�nutxt����K�a�t�h�y� �B�r�o�w�nutxt����J�e�a�n� �I�r�v�i�n�eutxt����K�a�t�h�y� �L�o�v�eutxt����K�i�m�i� �R�o�b�e�r�t�s�o�nutxt����E�d� �S�u�m�p�t�e�rutxt����J�o� �C�u�m�m�i�n�sutxt����K�i�m� �B�o�w�e�rutxt����M�i�k�e� �F�u�l�l�e�rutxt����C�a�t�h�y� �R�e�e�dutxt����J�o�y�c�e� �U�n�d�e�r�w�o�o�dutxt����D�a�p�h�n�e� �E�s�h�o�mutxt����K�a�t�h�y� �B�r�o�w�nutxt����D�a�v�e� �R�a�m�e�yutxt����M�a�r�k� �D�e�R�o�u�s�i�eutxt����T�o�m� �B�l�o�r�eutxt����P�a�u�l� �B�e�c�kutxt����K�e�l�l�y� �J�o�h�n�s�o�nutxt����A�l�a�n� �B�u�r�w�e�l�lutxt����S�h�e�r�y�l� �B�u�r�l�e�yutxt����V�i�v�i�a�n� �L�a�n�d�v�i�kutxt����M�a�r�k� �H�c�H�u�g�hutxt����J�i�m� �N�e�w�t�o�nutxt����C�h�u�c�k� �T�u�r�n�e�rutxt���� 

所以它會好一段時間,但最後沒有逗號,而是gobblygook這是無法使用的。我哪裏錯了?

回答

0

不知道究竟我變了,但現在它工作.....

tell application "Adobe InDesign CS5.5" 
set myagents to (name of properties of every asset of library "Agents.indl" as list) 
end tell 

set agentlist to "" 
set myagents to my simple_sort(myagents) 
repeat with currentagent in myagents 
set agentlist to agentlist & (currentagent) & "," 
end repeat 
set x to count agentlist 
set agentlist to characters 1 thru (x - 1) of agentlist as string 
my write_agents(agentlist) 


on write_agents(this_list) 
    set the agent_log to ("/Volumes/RealEstate/agents.txt" as POSIX file) 
    try 
     set eof of agent_log to 0 
     open for access file the agent_log with write permission 
    write (this_list) to file the agent_log starting at eof 
    close access file the agent_log 
on error 
    try 
     close access file the agent_log 
    end try 
end try 
end write_agents 


on simple_sort(my_list) 
    set the index_list to {} 
set the sorted_list to {} 
repeat (the number of items in my_list) times 
    set the low_item to "" 
    repeat with i from 1 to (number of items in my_list) 
     if i is not in the index_list then 
      set this_item to item i of my_list as text 
      if the low_item is "" then 
       set the low_item to this_item 
       set the low_item_index to i 
      else if this_item comes before the low_item then 
       set the low_item to this_item 
       set the low_item_index to i 
      end if 
     end if 
    end repeat 
    set the end of sorted_list to the low_item 
    set the end of the index_list to the low_item_index 
end repeat 
return the sorted_list 
end simple_sort 
相關問題