2017-07-23 29 views
0

我有一個列表,我希望此列表(訂購號) 中的每個元素都能運行搜索,從chrome中抓取文本並使用網站導航這個訂單號。爲AppleScript上的每個項目運行子腳本

我已經兩個腳本(A和B)

我想我可以只添加我長的腳本(B)到第一個,裏面

repeat with theItem in theResult 
Script B 
end repeat 

,但是這是不工作,我得到的錯誤

預計「結束」,但發現「屬性」

腳本B例如:

tell application "Google Chrome" 
    tell front window's active tab to set infoGrab to execute javascript "document.getElementsByClassName('even')[2].innerHTML;" 
end tell 

set theText to Unicode text 
set theSource to infoGrab 
property leftEdge72 : "<a href=\"/" 
property rightEdge72 : "\">" 
set saveTID to text item delimiters 
set text item delimiters to leftEdge72 
set classValue to text item 2 of theSource 
set text item delimiters to rightEdge72 
set uniqueIDKey to text item 1 of classValue 
set text item delimiters to saveTID 
uniqueIDKey 

以及更多。

我又試圖保存在一個獨立的腳本,腳本B和從腳本一個這樣

repeat with theItem in theResult 
    set the clipboard to theItem 
    set myScript to load script file ((path to desktop folder as text) & "SEARCH.scpt") 
    tell myScript 
    end tell 
    delay 30 
end repeat 

運行,但這種不工作都不是,腳本B時,由於忽略所有重複和延遲的,只是運行一切即時性,沒有在谷歌Chrome上的行動

問:如何做一個列表中的每個元素,包括文本分隔符和更多的其他行動。 PS:抱歉,如果我的帖子很混亂。

+0

您的標題意味着答案。你必須告訴'myScript'來運行** – vadian

+0

是的,這是合理的和工作的,謝謝!不幸的是,對於我來說腳本在幾秒鐘後仍然失敗(但是當他自己運行時沒有問題) –

回答

0

我覺得你的劇本是有缺陷的,因爲「劇本B」不使用「theItem」從重複循環變量。因此,「腳本B」將爲每個項目返回相同的結果。

您的目標不明確。也許如果你提供了更多的細節,可以使用源HTML和預期結果的實際示例數據,我們可以提供更好的幫助。

IAC,你爲什麼要調用腳本而不是使用處理程序? 這裏是你的腳本重構使用處理程序,作爲一個例子。

repeat with theItem in theResult 
    ## You don't seem to use "theItem" in the Script B ## 
    # if so, then the getID() handler will return the same results for all items in this loop 

    set myID to my getID() 
end repeat 

on getID() -- was Script B 
    -- put in same script file, or in script library 
    -- does this need to have a parameter? 

    tell application "Google Chrome" 
    tell front window's active tab to set infoGrab to execute javascript "document.getElementsByClassName('even')[2].innerHTML;" 
    end tell 

    set theText to Unicode text 
    set theSource to infoGrab 
    set leftEdge72 to "<a href=\"/" 
    set rightEdge72 to "\">" 

    set saveTID to text item delimiters 
    set text item delimiters to leftEdge72 
    set classValue to text item 2 of theSource 
    set text item delimiters to rightEdge72 
    set uniqueIDKey to text item 1 of classValue 
    set text item delimiters to saveTID 
    return uniqueIDKey 
end getID 
0

運行腳本別名((路徑桌面文件夾中的文字)&「SEARCH.scpt」)

相關問題