【发布时间】:2019-07-02 01:22:15
【问题描述】:
我正在创建一个 AppleScript 来控制 SAP 中的一些基本标准操作,并且从可用事务的主菜单页面中编写的所有内容都可以正常工作。当前脚本填写命令文本字段并打开一个新的现有事务代码。但是,一旦 SAP 进入新事务代码页,当我第二次运行 AppleScript 时,它不再识别命令文本字段的索引。相反,它将事务代码粘贴到恰好是当前焦点的任何文本字段中。当我运行脚本时,它应该总是转到相同的文本字段,因为整体索引地址没有改变,但事实并非如此。
我试图打开 SAP 的脚本字典,但我公司的 SAP 版本似乎禁用了脚本字典,所以我不得不使用索引地址来填充文本字段并单击按钮
on chooseSAPTransaction()
global sapTransaction, transactionCode
set transactionCode to "" -- intialize the variable
set transactionList to choose from list {"Find Document", "Change Document", "Look up Product", "Correct Product"} with prompt "SAP Action:" default items {""}
if transactionList is false then
error number -128
else
set choosenTransaction to item 1 of transactionList
end if
if choosenTransaction is "Find Document" then
set transactionCode to "code1"
chooseCode1()
end if
if choosenTransaction is "Change Document" then
set transactionCode to "code2"
chooseCode2()
end if
if choosenTransaction is "Look up Product" then
set transactionCode to "code3"
chooseCode3()
end if
if choosenTransaction is "Correct Product" then
set transactionCode to "code4"
chooseCode4()
end if
set sapTransaction to "/n" & transactionCode
activate application "SAP"
delay 0.1
tell application "System Events"
tell process "SAP"
tell front window to tell toolbar 1 to tell text field 1
keystroke sapTransaction
end tell
tell front window to tell toolbar 1 to tell button 1 to perform action "AXPress"
end tell
end tell
end chooseSAPTransaction
在随后的脚本执行中,它会跳过 tell front window to tell toolbar 1 to tell text field 1 并直接转到 keystroke sapTransaction
("/n" & transactionCode 创建一个字符串,告诉 SAP 新事务要转到。手动键入时,它总是将您带到新事务,无论您在当前事务中可能有多少层)
我希望索引指令在运行脚本的每个新实例上都转到相同的元素,但是一旦运行一次,AppleScript 就不再找到元素地址了。
编辑:
我只是尝试将粘贴操作移动到它自己的唯一处理程序中,以便在尝试进入下一步之前可以调用它,但这也不起作用。
--剪辑--
if choosenTransaction is "Find Document" then
set transactionCode to "code1"
set sapTransaction to "/n" & transactionCode
pasteTransaction()
chooseCode1()
end if
--剪辑--
on pasteTransaction()
global serialNumber, sapTransaction, transactionCode
activate application "SAPGUI"
delay 0.1
tell application "System Events"
tell process "SAPGUI"
tell front window to tell toolbar 1 to tell text field 1
keystroke sapTransaction
end tell
tell front window to tell toolbar 1 to tell button 1 to perform action "AXPress"
end tell
end tell
end pasteTransaction
编辑 2:
我通过强制 SAP 浏览菜单使其工作。哇!
on pasteTransaction()
global serialNumber, sapTransaction, transactionCode
activate application "SAPGUI"
delay 0.1
tell application "System Events"
click menu item ¬
"Target Command Field" of menu 1 of menu bar item ¬
"Edit" of menu bar 1 of application process "SAPGUI"
keystroke sapTransaction
tell process "SAPGUI"
tell front window to tell toolbar 1 to tell button 1 to perform action "AXPress"
end tell
end tell
end pasteTransaction
不幸的是,这并不能解决 AppleScript 没有为文本字段找到正确索引地址的更大问题,因为让这部分工作只是第一步。现在我必须将文本字符串放入每个事务中的各种文本字段中。
因此,如果有人知道如何解决原始索引地址问题,那就太好了。
我希望我知道如何实际编写 AppleScript,而不是一次将来自不同来源的一个动作拼凑在一起。它并不优雅,而且功能很简单。
【问题讨论】:
-
我需要弄清楚如何让这些索引地址正常工作。我开始使用下一个处理程序,唯一能让它到达正确文本字段的方法是通过关键代码选项卡,这不仅笨拙,而且如果您的 SAP 副本与服务器的通信速度比我的慢,它也会中断。如果没有以相同的速度连接,则光标最终会出现在错误的字段中并单击错误的单选按钮。呕吐。
标签: applescript