我设置了一个改变iTunes中当前歌曲评级的AppleScript,它在前几次有效,但现在什么也没做.这是代码:
tell application "System Events"
if (name of processes) contains "iTunes" then
set iTunesRunning to true
else
set iTunesRunning to false
end if
end tell
if iTunesRunning then
tell application "iTunes"
repeat with theTrack in (get selection)
set the rating of theTrack to 100
end repeat
end tell
end if
Run Code Online (Sandbox Code Playgroud)
有人在那里看到任何明显的问题吗?仅供参考,这是一个全球热键,但即使在Applescript编辑器中打开它并点击"Run"也不会做任何事情.
我是Apple的新手,目前卡在访问提示窗口,要求输入密码.
我正在为我的日常使用应用程序创建一个启动器,我想自动启动启动过程.
现在,我只推出了两个应用程序VirtualHostX和MAMP.后来我可能会添加一些.
这是我到目前为止所做的:
tell application "VirtualHostX" to activate
tell application "MAMP" to activate
tell application "System Events"
tell process "VirtualHostX"
tell menu bar 1
tell menu bar item "Web Server"
tell menu 1
click menu item "Start"
end tell
end tell
end tell
end tell
end tell
Run Code Online (Sandbox Code Playgroud)
启动时,它将成功启动两个应用程序,但虚拟主机将询问我的密码以进行授权.我想在流程或代码中集成输入密码.我已经尝试谷歌寻求答案,但未能找到解决方案.
我似乎无法定位该窗口并输入我的密码.

让我知道我错过了什么.
谢谢.
我正在尝试使用Applescript在Xcode中创建一个应用程序来转换PDF.
问题是我需要Xcode/AppleScript等待每个'do shell script'命令在开始下一个之前完成处理.
有没有办法检测每个脚本是否已完成?
例如
tell application "System Events"
do shell script "/opt/local/bin/convert task1.tif output1.pdf"
end tell
tell application "System Events"
do shell script "/opt/local/bin/convert task2.tif output2.pdf"
end tell
Run Code Online (Sandbox Code Playgroud)
谢谢,安东尼
我正在尝试编写一个可以在终端的多个选项卡中运行多个命令的脚本.我发现了很多关于它的信息,但它并不像我想要的那样工作.所以我可能需要AppleScript.
•此代码在新窗口中运行命令:
tell app "Terminal"
do script "echo hello"
end tell
Run Code Online (Sandbox Code Playgroud)
•这一个打开一个新选项卡
tell application "Terminal"
activate
tell application "System Events"
keystroke "t" using {command down}
end tell
end tell
Run Code Online (Sandbox Code Playgroud)
但我没想出如何"混合"它们.任何的想法 ?
我正在尝试编写一个automator服务来启动终端中的virtualhost.sh.
使用"服务"上下文菜单,对话框将打开以询问虚拟主机的名称,然后运行applescript以启动终端并传入输入文本.
我想要的是将我的用户名和密码传递给管理员权限,这样我就不需要在终端中使用sudo传递它.
这可以用do shell script但是执行a bin/sh和virtualhost.shbash脚本来完成,所以我得到了错误bin/sh: virtualhost.sh command not found
或者我可以使用,do script with command但这不允许我传入用户名和密码.
我的代码看起来像这样:
on run {input, parameters}
set vhost to "virtualhost.sh " & input
tell application "Terminal"
activate
do shell script vhost user name "user" password "pass" with
administrator privileges
end tell
end run
Run Code Online (Sandbox Code Playgroud)
这会产生前面提到的bin/sh错误.
同 do script with command
on run {input, parameters}
set vhost to "virtualhost.sh " & input
tell application "Terminal"
activate
do script …Run Code Online (Sandbox Code Playgroud) 我正在创建一个应用程序,我想检查我的计算机是否已经安装了一个应用程序(Example.app,com.example.test),并能够将该应用程序发送到Mac App Store.
我尝试了几件事,比如:
NSString *script = @"try\r tell application \"Finder\" to get application file id \"com.example.test\"\r set appExists to true\r on error\r set appExists to false\r end try";
NSAppleEventDescriptor *result = [self executeScript:script];
return [result booleanValue];
Run Code Online (Sandbox Code Playgroud)
这非常有效,但我一直在阅读Apple在权利文件中不允许Finder的临时例外,以保证应用程序的安全.
我也尝试了类似的东西,但避免使用Finder:
NSString *script = @"set appID to id of application \"Example\"\r set msg to exists application id appID\r tell application \"Example\" to quit\r return msg";
NSAppleEventDescriptor *result = [self executeScript:script];
return [result booleanValue];
Run Code Online (Sandbox Code Playgroud)
这仅在用户拥有应用程序时有效,否则,它将提示询问应用程序位置的对话框.(并在Dock中显示示例图标几毫秒)
我也一直在尝试一些更多的hacky解决方案,如:
NSTask *task = [NSTask new];
[task setLaunchPath:@"/bin/bash"]; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用NSAppleScript从Objective-C执行一些AppleScript ...但是,我正在尝试的代码是Yosemite中用于自动化的新JavaScript.它在运行时似乎没有做任何事情,但是,正常的AppleScript工作正常.
[NSApp activateIgnoringOtherApps:YES];
NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:
@"\n\
iCal = Application(\"Calendar\");\n\
iCal.includeStandardAdditions = true;\n\
iCal.activate();\n\
iCal.displayAlert(\"testing\");\n\
"];
[scriptObject executeAndReturnError: nil];
Run Code Online (Sandbox Code Playgroud)
我怎么能让它运行?
谢谢
javascript cocoa applescript objective-c javascript-automation
我目前正在编写一个超级简单的脚本,我需要在变量中找到并替换文本(特别是在放到AppleScript上的项目的路径中.)这是我目前的情况:
on open {dropped_items}
tell application "Finder" to set filePathLong to the POSIX path of dropped_items as text
on replaceText(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to "" & subject
set text item delimiters of AppleScript to prevTIDs
return subject
end replaceText
get replaceText("/mpc/mayors1", "/ifs/disk1", filePathLong)
display dialog subject
end open …Run Code Online (Sandbox Code Playgroud) 我1Password用来存储我的密码,并fluid.app创建一些特定于站点的应用程序/浏览器
虽然1Password与Chrome,Safari和其他浏览器很好地集成,但它与Fluid应用程序并不相称,这是我的麻烦所在.
因此Keyboard Maestro,当我在Fluid应用程序中时,我创建了一个快捷方式(with )来运行一个applecript来打开mini.但是,我似乎无法获得推出迷你版的AppleScript.以下是我的尝试:
tell application "1Password mini" to launch 什么都不做,虽然AppleScriptEditor没有报告任何错误tell application "1Password mini" to open 什么都没有,虽然AppleScriptEditor没有报告任何错误tell application "1Password mini" to activate没有意义,因为1Password mini已经激活了tell application "1Password" to open打开主1Password应用程序,而不是mini,这是我需要的.有趣的是,当我运行(1),(2),(3),AppleScriptEditor自动替换1Password mini用2BUA8C4S2C.com.agilebits.onepassword-osx-helper,不为我澄清一下事情的.
有没有人知道如何解决这个问题?
我在OSX 10.10.2(优胜美地),如果重要的话
一行摘要-我正在寻找一种使AppleScript本身公开的名称,该名称期望特定的窗口内容(UI元素)在“ tell”语句中被提及。
如何使AppleScript列出希望我用来引用窗口内容的名称?
例如我可以说 tell current application to tell its front window's list 1 to ...
我正在尝试为窗口的所有内容查找类似于“列表1”的术语,以便可以将其与Accessibility Inspector中的列表进行交叉引用。
我尝试了这段代码,但是第一行生成了一个错误,提示“错误”无法将应用程序“系统事件”的“ class prcs” \“ iTunes”的窗口1的“ class ects”的名称键入字符串。 “从«class prcs»窗口1的«class ects»的名称到iTunes的数字-1700到字符串”
tell application "System Events" to tell process "iTunes" to set elementNames to the names of the entire contents of its front window as string
tell application "TextEdit"
activate
make new document at the front
set the text of the front document to elementNames
set WrapToWindow to text 2 thru -1 of (localized …Run Code Online (Sandbox Code Playgroud) applescript ×10
macos ×3
cocoa ×2
objective-c ×2
shell ×2
automation ×1
bash ×1
command-line ×1
itunes ×1
javascript ×1
replace ×1
terminal ×1
xcode ×1