我是AppleScript的新手,所以这是一个真正的基本问题,但我找不到AppleScript参考中的答案或示例.指南.
我做一个简单的脚本,我会捆绑为一个应用程序文件,在编辑器中的AppleScript,我可以看到应用程序的Bundle Contents,其中我有一个图标,一个描述文件和Scripts文件夹.如何从脚本访问该内容以及如何访问内部的脚本scripts folder?
我找到了一些脚本如何通过AppleScript控制Spotify.但它们只包括播放/暂停,下一个,上一个,停止等内容.我正在寻找Spotify for AppleScript的一些参考资料,但我没有找到任何参考资料.
是否可以使用AppleScript将Spotify中的当前播放曲目添加到特定播放列表,然后为该脚本分配系统范围的快捷方式?
最终,我正在尝试分配热键(通过Alfred或Keymando),可以将最前面的应用程序移动到我的任何空间.触发一个AppleScript似乎是最有可能取得成功的途径.我经常环顾四周,似乎有一种方法可以通过applescript中的"space preferences"来实现这一点,但这在OS X Lion中消失了.
我想在用户离开或返回计算机时启动脚本.AppleScript中是否有任何内置方法来检查用户的状态?如果不是我可以在OS X中使用什么?
我需要计算每个应用程序的所有窗口.我试图这样做的每一种方式,我只得到分配给当前(任务控制)桌面的窗口数.(我目前正在运行Mac OS X 10.7,所以后空间.)有没有办法在所有桌面上获得所有窗口的每个应用程序数量?
我试过的关键:
tell application "System Events"
repeat with _app in (every process whose visible is true)
tell _app
log (name as string) & ": " & (count of every window)
end tell
end repeat
end tell
Run Code Online (Sandbox Code Playgroud)
请注意,该whose visible is true子句不是问题.它找到了所有适当的进程,但是一旦我询问了windows的进程,它们只计算活动桌面中的进程.
我试过把log线拉出来tell并使用name of _app和count of every window of _app,但是没有区别.我尝试过除了processes 以外的东西System Events,但是任何有用的东西最终都会有效地成为获得同一个对象的另一种方式.我已经尝试过迭代UI elements,但没有窗口显示不在当前桌面上,虽然我确实为每个应用程序获得了菜单栏.
我很好地迭代所有桌面(虽然实际上没有切换到所有桌面),但我甚至找不到获取桌面列表的方法. 这个答案声称描述了如何做到这一点,但我只在里面得到一个元素every desktop.并不是说有一个明显的方法来获得Windows,无论如何你有这个桌面对象.
值得指出的是台式机是由Dock控制的,而不是由Mission Control控制的.我不知道AppleScript与Dock交谈的方式,所以如果你知道某些事情,那么对此的回答或评论可能会帮助我指出正确的方向.
我想做一些不可能的事吗?
我目前正在使用AppleScript编辑器.我在那里运行以下代码:
tell application "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL"
call soap {method name:"CelsiusToFahrenheit", method namespace uri:"http://www.w3schools.com/webservices/", parameters:{Celsius:50 as string}, SOAPAction:"http://www.w3schools.com/webservices/CelsiusToFahrenheit"}
end tell
Run Code Online (Sandbox Code Playgroud)
如果我执行上面的代码,我会得到一个"错误"字符串(这不是我的预期).生成的请求如下:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<m:CelsiusToFahrenheit xmlns:m="http://www.w3schools.com/webservices/">
<Celsius xsi:type="xsd:int">50</Celsius>
</m:CelsiusToFahrenheit>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)
如果我像这样编辑请求(我使用Fiddler来编辑请求):
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/">
<Celsius xsi:type="xsd:int">50</Celsius>
</CelsiusToFahrenheit>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)
我收到"122",这是正确的答案.
我的问题是:
我在Xcode的Interface Builder中,创建了一个Cocoa-Applescript自定义Automator Action.我在界面中有一个Button和一个ComboBox菜单.我想在用户单击Button时填充ComboBox菜单的内容值.我创造了
on buttonSentAction_(sender)
-- set popupMenuContentValues of my parameters() to aList as list
my popupMenu's addItemsWithObjectValues_(aList)
end buttonSentAction_
Run Code Online (Sandbox Code Playgroud)
在applescript文件中的处理程序,但当我从按钮拖动到文件的所有者时,文件的所有者不会突出显示我放弃连接.我期待的是它放弃并让我选择buttonSentAction_处理程序来接收发送的动作.如果我右键单击File's Owner,我在Applescript控制器文件中创建的收到的操作处理程序不会显示.(注意,我仍然不确定在该处理程序中填充ComboBox菜单的正确行.)

我可以在"FM to Named Text Boxes"中看到示例macosxautomation.com上的Automator Action项目在IB中有一个按钮,您可以在Bindings Inspector中看到按钮的发送动作实际上已连接到文件所有者,并且applescript文件具有匹配的处理程序.另外,我默认将File's Owner的控制器设置为applescript文件.显然,我遗漏了一些关于在Automator Action Project中挂起已发送动作的具体内容.有帮助吗?
我可以使用以下方法在Numbers电子表格中设置单元格的格式:
tell application "Numbers"
activate
tell document 1
tell active sheet
set the selectedTable to ¬
(the first table whose class of selection range is range)
end tell
tell selectedTable
tell column "J"
set the format of cell 3 to number
end tell
end tell
end tell
end tell
Run Code Online (Sandbox Code Playgroud)
但是如何设置单元格的小数位数?
我的Applescripts自从我上次系统更新以来,我每天都运行以从Safari获取文本
它曾经只在Safari中工作,而不是在Safari预览版中工作,我想Safari预览系统现在可以用于Safari
tell application "Safari"
set DinfoGrab to do JavaScript "
document.getElementsByClassName(' field type-string field-Dinfo ')[0].innerHTML;" in tab 3 of window 1
end tell
Run Code Online (Sandbox Code Playgroud)
有这个错误:
Safari出错:无法生成"document.getElementsByClassName('field type-string field-Dinfo')[0] .innerHTML;" 到文本类型.
我该如何解决这个问题?谢谢.
更新:
以下是与Chrome完美配合的内容:
tell application "Google Chrome"
tell tab 3 of window 1 to set r to execute javascript "document.getElementsByClassName('field type-string field-Dinfo')[0].innerHTML;"
end tell
Run Code Online (Sandbox Code Playgroud) applescript ×10
macos ×5
automation ×1
automator ×1
cocoa ×1
numbers ×1
osx-lion ×1
safari ×1
soap ×1
spotify ×1
spreadsheet ×1
variables ×1
web-services ×1
window ×1
xcode ×1