这只是让我疯了.我试图用bash读取文件,删除重复项,排序,然后通过applescript显示"列表选择"窗口.
我的$ DATALOG文件的格式如下:
field1 field2
field1 field3
field1 field4
等等...
AppleScript的=awk '{print $2}' $DATALOG | awk ' !x[$0]++' | sort -u | tr "_" " "| sed 's/^/\"/' | sed 's/$/\"/' | tr "\n" "," | sed 's/.$//'
现在,这条线路很棒.在$ Applescript中,我得到这样的输出:
"场2","场3","场4"
这正是我想要的.
现在,我接受输出,并在引号和applescript部分之前添加反斜杠.
Applescript=`echo "tell application \"System Events\" to return (choose from list {$Applescript})"| sed 's/\"/\\\"/g'`
Run Code Online (Sandbox Code Playgroud)
这让我得到了我想要的东西:
告诉应用程序\"系统事件\"返回(从列表{\"字段2 \",\"字段3 \",\"字段4 \"}中选择)
现在,我尝试osascript命令:
osascript -e $ Applescript
我收到一个错误:
4:4:语法错误:预期的表达式但发现脚本结束.(-2741)
所以,我添加引号:
osascript -e"$ Applescript"
我收到一个错误:
17:18:语法错误:预期的表达式,属性或密钥形式等,但发现未知令牌.(-2741)
我不知道这里到底发生了什么,所以我决定复制$ Airport的回声并尝试将其作为一个变量.
机场=
tell application …
我想确保一个applescript可以转换为bash.对于如何做到这一点有什么想法吗?如果是这样,我将在下面放一个简单的AppleScript,为您提供脚本运行方式的示例.更清楚一点,我只想要一个bash脚本或shell脚本来完成我的AppleScript正在做的事情.我希望它"启用"或更改系统首选项中的开关默认值,在"节能器"下读取...'电源故障后自动启动'...:
将uiScript设置为"单击复选框"在应用程序进程"系统首选项"的窗口组"1节能"列表2的电源故障后自动启动\"系统首选项"
运行脚本"告诉应用程序"系统事件\""&uiScript&"结束告诉"
谢谢,-Unimachead
在applescript中有一个说法命令.目标c有这样的东西吗?
谢谢,以利亚
我以为我可以这样做:
tell application "Mail"
activate
end tell
Run Code Online (Sandbox Code Playgroud)
虽然我可以看到顶部的邮件工具栏.它没有将邮件应用程序带到前面以使其完全可见.
我的录音机也不能用于某些原因,所以我无法用它来找出我需要做的事情.
我怎样才能做到这一点?
Tell application "System Preferences"
set "default voice" to "Agnes"
end tell
Run Code Online (Sandbox Code Playgroud)
结果是:
无法将"默认语音"设置为"anna".不允许访问.
我从来没有对AppleScript做过多少工作,但我正在尝试自动化这个过程.我有一个需要点击按钮的网站.但是按钮是用JavaScript/jQuery/AJAX实现的,如下所示:
<div id="divIdOfButton" class="someClass">
<div class="divClassOfButton someOtherClass">
<img src="imgOfButton">
<div>
...
<script type="text/javascript">
$(document).ready(function() {
$('#divIdOfButton .divClassOfButton).click(function() {
...
}}
Run Code Online (Sandbox Code Playgroud)
我没试过就试过这个
tell application "Safari"
activate
delay 1
set URL of first document to "http://example.com/"
do JavaScript "document.getElementById('divIdOfButton').getElementByClassName('divClassOfButton')[0].click()" in front document
end tell
Run Code Online (Sandbox Code Playgroud)
我做了一堆搜索,但找不到任何东西.非常感谢一些帮助.
多年来我一直使用以下Applescript来从Applescript中触发Time Machine.它似乎不再适用于Mac OS X 10.9 Mavericks.任何人都知道解决方案或替代方案.此脚本运行并且不会抛出任何错误消息.它什么都不做.
do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper >/dev/null 2>&1 &"
Run Code Online (Sandbox Code Playgroud) 我在Objective C中使用了这段代码:
@implementation KDOrderInfo
- (id)performDefaultImplementation {
NSString *theRequest = [self directParameter];
NSDictionary *arguments = [self evaluatedArguments];
NSLog(@"arguments = %@ %ld",arguments, [arguments count]);
NSLog(@"theRequest----> %@",theRequest);
/*.......
.....*/
return @YES
}
Run Code Online (Sandbox Code Playgroud)
这段代码在Objective C中运行正常.我将此代码转换为Swift代码,如下所示:
class OrderInfo : NSScriptCommand {
override func performDefaultImplementation() -> AnyObject! {
let theRequest: AnyObject! = self.directParameter
let arguments = self.evaluatedArguments
println("arguments = \(arguments) argumentsCount = \(arguments.count)")
println("theRequest----> \(theRequest)")
/*.......
.....*/
return "OK"
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行我的AppleScript然后我得到错误(InfoMaker是我的应用程序的名称):InfoMaker得到一个错误:处理程序某些对象未定义.
方法 :
override func application(theApp:NSApplication,delegateHandlesKey theKey:String) -> Bool{
println("scripting key = \(theKey)");
let …Run Code Online (Sandbox Code Playgroud) 我需要删除文本字符串AppleScript中的最后一个字符。事实证明,这比我想的要困难得多。有人可以解释如何做到吗?
我想知道是否有一种简便的方法可以将AppleScript列表转换为分隔每个项目的字符串。我可以以一种我想要的更长的方式来实现这一目标,所以我想知道是否有一种简单的方法可以实现这一目标。基本上,我想获取一个清单,例如{1,2,3}将其转换为string "1, 2, 3"。我可以做类似下面的事情,但是在结果字符串后面导致逗号:
set myList to {"1.0", "1.1", "1.2"}
set Final to ""
if (get count of myList) > 1 then
repeat with theItem in myList
set Final to Final & theItem & ", "
end repeat
end if
Run Code Online (Sandbox Code Playgroud) applescript ×10
macos ×4
bash ×2
list ×2
command ×1
javascript ×1
objective-c ×1
sed ×1
string ×1
swift ×1
timemachine ×1
unix ×1
voice ×1