我正在尝试为我编写的Cocoa应用程序添加一些脚本功能.我为我的项目创建了一个sdef(脚本定义文件).到目前为止,我已经成功地使用AppleScript访问对象子元素(元素),但我不能在生活中找出如何调用方法(命令).
这是我的sdef文件.
<suite name="mySuite" code="mSUI" description="My Application Suite">
<class name="application" code="capp" description="Top level scripting object.">
<cocoa class="NSApplication"/>
<!-- I can access these elements fine -->
<element description="Test children." type="child" access="r">
<cocoa key="myChildren"/>
</element>
<!-- Cannot seem to call this method :( -->
<responds-to command="testmethod">
<cocoa method="exposedMethod:"/>
</responds-to>
</class>
<class name="child" code="cHIL" description="A Child." plural="children">
<cocoa class="Child"/>
<property name="name" code="pnam" description="The child name." type="text" access="r">
<cocoa key="name"/>
</property>
</class>
<command name="testmethod" code="tEST" description="Execute the test method" />
</suite>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器类实现(这是我的应用程序的委托) …
我希望applescript一直向上滚动窗口.
我已经尝试过向上翻页键,主页键,我已经尝试使用窗口的内置滚动功能来寻找滚动方式,但到目前为止我甚至都无法移动滚动位置.
我有两个显示器设置,我试图在第二个显示器中定位应用程序的窗口,但我做的任何事情似乎都没有.例如,我正在使用我的笔记本电脑,终端窗口在屏幕上最大化.然后我插上一个外接显示器.然后我想运行applescript并让终端在更大的第二台显示器上最大化.
这就是我现在所拥有的:
set monitorTwoPos to {1050, -600}
set monitorTwoSze to {1200, 1920}
tell application "Microsoft Outlook"
set position of window 1 to monitorTwoPos
set size of window 1 to monitorTwoSze
end tell
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
/Users/vcutten/AppleScripts/SpacesWork.scpt:1291:1332: execution error: Microsoft Outlook got an error: Can’t make position of window 1 into type specifier. (-1700)
我很确定我只是使用设置位置和设置大小完全错误:(当我使用边界它有点工作...
奖金问题:如何在打开的窗户中循环并获得它们的大小?谢谢!
如何在safari中打开一个新窗口,然后使用苹果脚本在该窗口中打开包含不同URL的多个选项卡?
有谁知道该文件InfoPlist.strings是为了什么?它在Xcode 3.2中.它是Applescript中的Cocoa应用程序.
这可能是一个全新的问题,但在这里.我正在制作一个纯AppleScript应用程序.它激活另一个应用程序,然后键入.问题是,当它激活应用程序时,它不会将应用程序窗口置于最前面.我试着告诉应用激活:
tell application "app_name.app"
activate
tell application "System Events" to keystroke "test"
end tell
Run Code Online (Sandbox Code Playgroud)
有帮助吗?谢谢!
如果它们适合某种URL模式(例如,不是一组给定的URL),我想自动打印chrome窗口(没有对话框).
你能用苹果脚本吗?有人可以分享一个例子吗?(我没有Mac,所以我无法真正尝试自己)
我正在尝试使用以下命令创建AppleScript.我遇到的问题是第三行有错误.我lame直接在终端中使用该命令没有问题.此外,lame它不是原生Mac实用程序; 我自己安装了它.有人有解决方案吗?
do shell script "cd ~/Downloads"
do shell script "say -f ~/Downloads/RE.txt -o ~/Downloads/recording.aiff"
do shell script "lame -m m ~/Downloads/recording.aiff ~/Downloads/recording.mp3"
-- error "sh: lame: command not found" number 127
do shell script "rm recording.aiff RE.txt"
Run Code Online (Sandbox Code Playgroud) 我使用applescript以root权限启动我的脚本.
osascript -e "do shell script \"myscript.sh\" with administrator privileges"
Run Code Online (Sandbox Code Playgroud)
此文本显示在提示中:
osascript wants to make changes.
Type your password to allow this.
Run Code Online (Sandbox Code Playgroud)
如何将名称"osascript"更改为我的可执行文件名称?有没有办法在此提示中更改图标?
我正在使用macOS 10.13中的Automator应用程序创建NSUserAutomatorTask一个.workflow文件.
我通过variables属性将变量传递给工作流:
https://developer.apple.com/documentation/foundation/nsuserautomatortask/1418099-variables
父应用程序是沙盒..applicationScriptsDirectory当未设置变量时,或者在应用程序中设置相同的变量并在工作流中声明时,脚本位于并成功运行.
if let workflow = try? NSUserAutomatorTask(url: url) {
workflow.variables = ["randomVariable": "value"] // NOTE
workflow.execute(withInput: nil) { (value, error) in
if let error = error {
print(error) // No variable named "randomVariable"
}
}
}
Run Code Online (Sandbox Code Playgroud)
工作流无法运行并显示错误:
没有名为"randomVariable"的变量
但是,如果我编辑工作流并添加一个变量以匹配代码中的一个,那么一切都很好.
我不再收到错误,工作流程正确执行:
这是一个问题,因为我想将多条信息作为变量传递给任何潜在的工作流程,并且每个工作流程单独决定处理每个所需的参数.
我不想要求每个工作流声明我的应用程序可选择提供的变量.
请注意,在我的示例工作流程中,从不使用变量.我不希望声明它的额外要求.
有没有办法避免每个工作流声明我的应用程序在执行工作流时传递的变量?
或者,有没有办法检查工作流声明了哪些变量?然后我只能传递工作流实际使用的那些.
applescript ×10
macos ×6
cocoa ×2
automator ×1
bash ×1
objective-c ×1
printing ×1
privileges ×1
prompt ×1
safari ×1
scroll ×1
shell ×1
workflow ×1
xcode ×1