根据man页面pbpaste,
-Prefer {txt | rtf | ps}
tells pbpaste what type of data to look for in the pasteboard
first. As stated above, pbpaste normally looks first for plain
text data; however, by specifying -Prefer ps you can tell
pbpaste to look first for Encapsulated PostScript. If you spec-
ify -Prefer rtf, pbpaste looks first for Rich Text format. In
any case, pbpaste looks for the other formats if the preferred
one is not found. The …Run Code Online (Sandbox Code Playgroud) 我很好奇AppleScript是否可以访问浏览器中的每个特定选项卡并在其中执行一些javascript.
有人有想法吗?
javascript safari applescript google-chrome applescript-objc
是否有可能获得行号,脚本引发错误?
例:
try
set a to "abc" + "123"
on error line number num
display dialog "Error on line number " & num
end try
Run Code Online (Sandbox Code Playgroud) 我有一本关于AppleScript的书,我想知道我是否应该保留.我已经了解JavaScript.
据我所知,Apple最近在OS X中添加了JavaScript脚本支持.
这是否意味着我不再需要学习AppleScript来为OS X应用程序编写脚本,还是比它更多呢?你的想法将不胜感激.
上述问题是从想要让应用程序自动执行操作的应用程序用户的角度出发的.
关于应用程序开发人员(Cocoa)的事情怎么样?如果他们想让他们的应用程序可编写脚本,他们可以不学习AppleScript吗?
更新:添加了赏金.问题被重新定义(对AppleScript及其用户没有任何不尊重):鉴于我已经了解JavaScript,我还有什么理由学习AppleScript吗?您对此事的详细想法将不胜感激.
如果我打开了几个OS-X Terminal.app窗口,如何将一个终端窗口移动到另一个空间?
我很高兴使用任何脚本或编程语言来实现这一点,但更喜欢AppleScript或调用标准框架.
(注意,这只是移动应用程序的一个窗口而不是所有窗口.)
我有一系列AppleScript命令需要在AppleScript的单行中实现.代码如下.
delay 2
tell application "System Events" to keystroke "foo"
tell application "System Events" to keystroke return
Run Code Online (Sandbox Code Playgroud) 我遇到了一个使用一小部分Applescript的shell脚本的问题.当我使用Applescript编辑器编译它时,它可以工作.它不在shell脚本中.
44:49:语法错误:预期行结束但找到命令名称.(-2741)23:28:语法错误:预期行结束但发现"之后".(-2741)
这是shell代码:
osascript -e 'tell application "System Events" -e 'activate'
osascript -e 'tell process "Application 10.5" -e 'set frontmost to true' -e 'end tell'
osascript -e 'delay 1' -e 'keystroke return' -e 'delay 1' -e 'keystroke return'
end tell
Run Code Online (Sandbox Code Playgroud)
Applescript(有效):
tell application "System Events"
activate
tell process "Application 10.5"
set frontmost to true
end tell
delay 1
keystroke return
delay 1
keystroke return
end tell
Run Code Online (Sandbox Code Playgroud)
[更新]/[已解决]
这解决了我试图修改applescript以在shell脚本中工作的任何问题:
## shell script code
echo "shell script code"
echo "shell script code" …Run Code Online (Sandbox Code Playgroud) 我正在使用AppleScript,需要这样做:
set TextToWrite to " #!/bin/bash cd "$( dirname "$0" )" java -server -Xmx4G -jar ./craftbukkit.jar" "
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我需要在字符串中生成的文本中包含引号.我该怎么设置
#!/bin/bash cd "$( dirname "$0" )" java -server -Xmx4G -jar ./craftbukkit.jar"
Run Code Online (Sandbox Code Playgroud)
没有引号乱搞的AppleScript字符串?
我想列出所有范围内的蓝牙设备,理想情况下是主机名,但MAC地址就足够了.我需要一个执行主动扫描的命令,以便我可以查看我的设备是否在附近,而不是列出以前配对设备的设备.
我的用例是检测我的蓝牙耳机或iPhone是否在我的Mac范围内,以触发安全设置更改(例如sudo超时).我已经做了很多谷歌搜索,我似乎能找到的唯一的东西是iOS快速代码示例.我很满意OS X Swift代码示例,AppleScript,终端实用程序或指向优秀文档的指针.
到目前为止我已经看过这些选项了:
blued:打印一个mac地址列表,但是当设备进入或超出范围或连接时它们似乎没有改变,并且它们与主机名不匹配blueutil(brew install blueutil):仅打印电源状态,而不是设备名称bluetoothaudiod:没有可用的界面Bluetooth Explorer.appGUIdtrace来看看如何Bluetooth Explorer.app计算列表:困难不得已而为之编辑2017/01:找到这个SO答案,详细介绍如何在Swift中查找附近的设备:列出 Swift
中蓝牙设备范围内的设备
编辑2017/10:找到Swift 3和4.0的更新SO答案:使用Swift 3.0附近的蓝牙设备
所以我正在努力创建一个基本上自动发送imessage的applescript.我现在的工作是:
on run {msg, phoneNum}
tell application "Messages"
set serviceID to id of 1st service whose service type = iMessage
send msg to buddy phoneNum of service id serviceID
end tell
end run
Run Code Online (Sandbox Code Playgroud)
除了在开始新会话时不起作用外,这大部分都有效.当您将脚本运行到与消息中没有对话的号码时,会收到一条弹出警告,提示"您的消息没有任何收件人".但是,这会创建与该人的对话,并且当您再次运行相同的脚本时,它会起作用.
我想如果它第二次运行,必须有办法以某种方式创建一个新的对话,但我从来没有真正使用过AppleScript或者之前的任何脚本语言,所以我不知道该怎么做.
编辑:发布后我立刻想到了一个粗略的解决方法.如果在您发送消息之前发送空字符串,则可以创建新会话,并且它可以与现有会话一起使用.
on run {msg, phoneNum}
tell application "Messages"
set serviceID to id of 1st service whose service type = iMessage
send "" to buddy phoneNum of service id serviceID
send msg to buddy phoneNum of service id serviceID
end tell
end run
Run Code Online (Sandbox Code Playgroud)
虽然这有效,但我认为有一种比这更好/更优雅的解决方案.
applescript ×10
macos ×4
cocoa ×2
bluetooth ×1
imessage ×1
javascript ×1
line ×1
objective-c ×1
onerror ×1
osascript ×1
pasteboard ×1
rtf ×1
safari ×1
spaces ×1
swift ×1
syntax ×1
syntax-error ×1
try-catch ×1