我正在尝试构建一个xcode项目并通过iPhone模拟器通过AppleScript运行它.我知道xcodebuild,但它不允许你在模拟器中运行应用程序.我已经非常接近下面的脚本......
tell application "Xcode"
set targetProject to project of active project document
tell targetProject
set active build configuration type to build configuration type "Debug"
set active SDK to "iphonesimulator3.0"
end tell
if (build targetProject) is equal to "Build succeeded" then
launch targetProject
end if
end tell
Run Code Online (Sandbox Code Playgroud)
...但是build命令似乎没有服从活动的SDK属性,它总是默认为项目的基本SDK设置(例如iPhoneOS3.0而不是iPhonesimulator3.0)
有没有办法告诉build命令使用特定的SDK?我在雪豹上使用xcode 3.2.
我想创建一个函数,该函数从所述字符串的开头返回特定字符串的子字符串,但不包括另一个特定字符串的开头.想法?
所以类似于:
substrUpTo(theStr, subStr)
Run Code Online (Sandbox Code Playgroud)
因此,如果我输入substrUpTo("Today is my birthday", "my"),它将返回第一个参数的子字符串,但不包括第二个参数开始的位置.(即它会返回"Today is ")
我主要是一个Python程序员,它经常被描述为"可执行的伪代码".我使用了一点AppleScript,它似乎是我见过的最类似英语的编程语言,因为几乎所有运算符都可以是单词,它可以让你在任何地方使用"the"(例如,这个愚蠢的例子我只是想出了:
set the firstnumber to 1
set the secondnumber to 2
if the firstnumber is equal to the secondnumber then
set the sum to 5
end if
Run Code Online (Sandbox Code Playgroud)
是一个有效的AppleScript程序.有没有比这些更像英语的编程语言?
为了运行我的AppleScript程序,我必须打开它并选择"运行".我希望程序在我点击它时运行.我试图编译它,但它似乎没有区别或创建一个新文件.
我很欣赏已经有关于这个主题的问题,但是阅读了我能找到的内容(特别是这一篇:告诉AppleScript构建XCode项目),它们似乎都已经有几年了,答案似乎并不适用到当前版本的Xcode.
与链接的问题类似,我试图自动打开Xcode项目,构建它然后在iPhone模拟器(v4.3)中运行应用程序.有问题的项目是Selenium项目的iPhoneDriver(详见此处:http://code.google.com/p/selenium/wiki/IPhoneDriver)
基于另一个问题的答案,我编写了以下脚本:
tell application "Xcode"
open "/Users/<username>/Documents/Code/Selenium/iphone/iWebDriver.xcodeproj"
tell project "iWebDriver"
clean
build
try
debug
end try
end tell
end tell
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我运行这个时,我得到以下内容:
tell application "Xcode"
open "/Users/ben.adderson/Documents/Code/Selenium/iphone/iWebDriver.xcodeproj"
--> project document "iWebDriver.xcodeproj"
clean project "iWebDriver"
--> missing value
build project "iWebDriver"
--> missing value
debug project "iWebDriver"
--> error number -1708
end tell
Run Code Online (Sandbox Code Playgroud)
如果我只运行open命令,Xcode会毫无问题地打开项目.但是,只要我包含脚本的其余部分,Dock中的Xcode图标就会反弹,但除了上面的AppleScript编辑器之外,这就是我所得到的.
谁能告诉我我做错了什么?这是我第一次使用AppleScript或Xcode,所以我很难诊断问题.
我已经尝试过查看Xcode AppleScript字典,但没有实际的例子,我无法确定我需要的语法.
在此先感谢您的帮助!
如何在Applescript中抛出错误并退出?我希望有类似PHP die或exit命令的东西,以便"完成"对话框不会触发.
function1()
display dialog "completed"
on function1()
function2()
end function1
on function2()
exit //what do i use here?
end function2
Run Code Online (Sandbox Code Playgroud)
以下是我尝试过的答案:
function1()
display dialog "completed"
on function1()
function2()
end function1
on function2()
try
display dialog "Do you want to catch an error?" buttons {"Continue without error", "Cause an error"} default button 2
if button returned of result is "Cause an error" then
error "I'm causing an error and thus it is caught in 'on error'"
end …Run Code Online (Sandbox Code Playgroud) 在一个AppleScript中,我收到一个我要打开的文件路径.
文件路径的格式为" /Users/xxx/my/file/to/open.xyz".
我想用默认程序打开它.如果它是AVI,我需要用视频程序打开它,如果它是xls,有excel,......
我尝试了几件事但没有成功:
--dstfile contains the previous path
tell application "Finder"
activate
open document dstfile
end tell
Run Code Online (Sandbox Code Playgroud)
- >我收到错误1728,告诉我他无法获取文件
tell application "Finder"
activate
open document file dstfile
end tell
Run Code Online (Sandbox Code Playgroud)
- >在这里相同
tell application "Finder"
activate
open document POSIX file dstfile
end tell
Run Code Online (Sandbox Code Playgroud)
- >在这里相同
我确定该文件存在,因为我在此代码执行之前执行此操作:
if not (exists dstfile) then
display dialog "File isn't existing"
end if
Run Code Online (Sandbox Code Playgroud)
我不能使用...的synthax open.xyz因为我收到它作为参数.
请帮助我绝望:'(
答:基于答案,我最终得到了这个:
set command to "open " & quoted form of dsturl
do shell script command
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用AppleScript设置Messages.app聊天窗口的位置.
tell application "System Events"
set position of window 1 of application "Messages" to {100, 100}
end tell
Run Code Online (Sandbox Code Playgroud)
使用此代码我收到一个错误:
error "Messages got an error: Can’t set «class posn» of window 1 to {100, 100}."
number -10006 from «class posn» of window 1
Run Code Online (Sandbox Code Playgroud)
那是什么意思?
如果我使用Finder尝试相同的代码,它可以工作.但是大多数其他应用程序都不起作用.
Applescript新手问题:)我正在尝试创建一个小AppleScript,允许我从当前运行的应用程序列表中选择多个项目,然后退出所选的应用程序.这样的东西可以工作,但不必点击每个对话框,从列表中选择会更容易.
tell application "System Events"
repeat with p in every process
if background only of p is false then
display dialog "Would you like to quit " & name of p & "?" as string
end if
end repeat
end tell
Run Code Online (Sandbox Code Playgroud)
任何和所有的帮助将不胜感激!
谢谢!
在Mac OS X <= 10.10上,我可以运行以下命令来打开VPN连接窗口:
function go-vpn {
/usr/bin/env osascript <<-EOF
tell application "System Events"
tell current location of network preferences
set VPN to service "LF VPN"
if exists VPN then connect VPN
repeat while (current configuration of VPN is not connected)
delay 1
end repeat
end tell
end tell
EOF
}
Run Code Online (Sandbox Code Playgroud)
这将打开连接窗口(与从VPN下拉列表中选择"LF VPN"网络相同).但是,在El Capitan,我收到以下错误:
execution error: System Events got an error: Can’t get current configuration of service id "18E8C59B-C186-4669-9F8F-FA67D7AA6E53" of network preferences. (-1728)
Run Code Online (Sandbox Code Playgroud)
如何在El Capitan中完成相同的操作,如何调试?
applescript ×10
macos ×4
xcode ×2
appleevents ×1
automation ×1
cocoa ×1
executable ×1
finder ×1
function ×1
iphone ×1
methods ×1
nlp ×1
scripting ×1
selenium ×1
string ×1
substring ×1
xcode4 ×1