为AppleScript上的每个项目运行子脚本

问题描述:

我有一个列表,我希望此列表(订购号) 中的每个元素都能运行搜索,从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

是的,这是合理的和工作的,谢谢!不幸的是,对于我来说脚本在几秒钟后仍然失败(但是当他自己运行时没有问题) –

我觉得你的剧本是有缺陷的,因为“剧本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 

运行脚本别名((路径桌面文件夹中的文字)&“SEARCH.scpt”)