0

我编写了我的第一个脚本,用于通过 Apple 的 autoingestion.class 下载下载报告。它在 OSX 10.7.5 上大部分时间都可以正常工作,但在 OSX 10.8 下,它有时会重命名文件或将终端文本放入 applescript 编辑器本身。

任何人都知道如何解决/改进这个?

tell application "Terminal"
activate
delay 1 #give time to activate Terminal

tell application "System Events"
    keystroke "cd " & ingestPath #path to autoingestion.class
    keystroke return
    keystroke "java Autoingestion " & userName & " " & userPW & " " & vendorID & " S D S " & reportDate
    keystroke return
end tell

delay 0.1
set frontWindow to window 1
repeat until busy of frontWindow is false
    delay 1
end repeat
#display dialog "finished"
#quit end tell

谢谢你的时间伙计们

Edit1:谢谢 您的快速回答!我尝试了第二部分,它给了我一个 Java 错误,有什么想法吗?一旦我再次拿到另一台 Macbook,我就会尝试延迟。

MacBook-Pro:~ USER$ java '/Volumes/STICK/Projekte/App_Statstiken/Apple/sales/Autoingestion' USERNAME PW VENDORID S D S 20130718
Exception in thread "main" java.lang.NoClassDefFoundError: /Volumes/STICK/Projekte/App_Statstiken/Apple/sales/Autoingestion
Caused by: java.lang.ClassNotFoundException: .Volumes.STICK.Projekte.App_Statstiken.Apple.sales.Autoingestion
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

Edit2: 仅供参考:更新到新的 autoingestion.class,它使用属性来保存 userName 和 userPW。

set exePath to ingestPath 
do script "java -cp " & (exePath & space & "Autoingestion autoingestion.properties" & space & vendorID & " S D S " & reportDate)

给出了autoingestion.properties缺失的错误,尽管如此

keystroke "java Autoingestion " & "autoingestion.properties" & " " & vendorID & " S D S " & reportDate 

正在工作中。我试图将路径放在属性文件的前面,但没有帮助。有任何想法吗?

在职的:

do script "cd " & ingestPath & ";java Autoingestion " & userName & " " & userPW & " " & vendorID & " S D S " & reportDate
4

1 回答 1

0

多次击键时,applescript 代码的运行速度比计算机界面执行打字的速度要快……所以你遇到了问题。解决方案是在键入命令之间设置短暂的延迟,以使计算机界面有时间执行键入。此外,您的系统事件代码不应位于“告诉应用程序终端”代码块内。

试试这个。您可以根据需要使用 normalDelay 和 shortDelay 时间来使它们更长或更短。

set normalDelay to 1
set shortDelay to 0.2

tell application "Terminal" to activate
delay normalDelay --give time to activate Terminal

tell application "System Events"
    keystroke "cd " & ingestPath --path to autoingestion.class
    delay shortDelay
    keystroke return
    delay shortDelay
    keystroke "java Autoingestion " & userName & " " & userPW & " " & vendorID & " S D S " & reportDate
    delay shortDelay
    keystroke return
    delay shortDelay
end tell

tell application "Terminal"
    set frontWindow to window 1
    repeat until busy of frontWindow is false
        delay normalDelay
    end repeat
end tell

display dialog "finished"

注意:我还没有尝试过,但是您可以按如下方式简化代码...

set exePath to ingestPath & "Autoingestion"

tell application "Terminal"
    activate
    do script "java " & quoted form of exePath & space & userName & space & userPW & space & vendorID & " S D S " & reportDate

    set frontWindow to window 1
    repeat until busy of frontWindow is false
        delay 1
    end repeat
end tell

display dialog "finished"

编辑:如果您遇到路径问题和其他错误(如您的评论中所示),那么这种方法可能会奏效。试试这个作为你的脚本命令。如果击键方法有效,那么这将起到同样的作用。

do script "cd " & ingestPath & ";java Autoingestion " & userName & " " & userPW & " " & vendorID & " S D S " & reportDate
于 2013-07-29T07:35:23.830 回答