I am trying to get Xcode to build and run my project using Applescript. This is the same question as How to build & run Xcode with Applescript?, but I think that answer may be out of date, since it doesn't work on my machine. I get this:
execution error: Xcode got an error: The specified object is a property, not an element. (-10008)
I've also tried the following:
tell application "Xcode"
build project "MyProject"
end tell
but it doesn't build, it just returns "missing value".
(Using Xcode 4.0.1, OS X 10.6.8)
I've been having a huge amount of trouble trying to use Applescript with Xcode; I can't find any actual documentation (except the Xcode dictionary, which is very terse), just examples that don't seem to work. Any help would be appreciated.
I'm going to venture to guess that this is an incomplete implementation on Apple's part. The Dictionary states that build is supposed to return a value, but nothing is returned and Xcode does nothing. The following code conforms to the Dictionary exactly, but it doesn't work either.
tell application "Xcode"
set theProject to project 1
set theBuildConfigType to build configuration type 2 of theProject -- "Debug"
set projectBuilt to build theProject using theBuildConfigType without static analysis and transcript
end tell
Just for reference here is the syntax per Script Debugger:
set theResult to build reference ¬
static analysis boolean ¬
transcript boolean ¬
using build configuration type
In Xcode 13, you can do:
tell application "Xcode"
set theProject to active workspace document
set actionResult to build theProject
repeat
if completed of actionResult is true then
exit repeat
end if
delay 0.5
end repeat
set actionResult to run theProject
repeat
if completed of actionResult is true then
exit repeat
end if
delay 0.5
end repeat
end tell
Related
I have tried the following:
tell application "Things3"
set newToDo to duplicate project "project1" to list "Today" with properties {name:"project2"}
end tell
and I get
Things3 got an error: Projects can not be copied. (-1717)
Now I have manually created project2 and I'm trying
tell application "Things3"
repeat with aToDo in to dos of project "project1"
duplicate aToDo to project "project2"
end repeat
end tell
Which gives me
Things3 got an error: Can’t set project "project2" to item 1 of every to do of project "project1".
I'm inferring that I have the Applescript syntax wrong for this second one.
However, while experimenting, I saw an error about not being able to move objects to a project container but I've forgotten what code it was. Is there a way to do this?
Having some trouble calling Cocoa methods from within AppleScript. For example, running the following snippet of code produces an error when ran using osascript:
set sharedWorkspace to call method "sharedWorkspace" of class "NSWorkspace"
Here's the thrown exception: Expected “,” but found identifier. (-2741) Should this code be nested under a tell statement? If so, what application should I be talking to?
Thanks.
call method looks like something out of the old AppleScript Studio, which was deprecated in 10.6 Snow Leopard and has since been removed.
There are a couple of prerequisites for calling Cocoa methods - a regular script needs to declare that it uses the desired framework(s), and the various classes and enums are defined at the application level and thus need to be prefaced with current application, or an object needs to exist to send the message to.
With that said, Cocoa methods can be called in a few different ways - using your snippet, for example:
use framework "Foundation"
set sharedWorkspace to current application's NSWorkspace's sharedWorkspace
-- or --
set sharedWorkspace to sharedWorkspace of current application's NSWorkSpace
-- or --
tell current application's NSSharedWorkspace's sharedWorkspace
set sharedWorkspace to it
end tell
The first form is what you will normally see used, as it is the closest to the Objective-C form. The appendix in the Mac Automation Scripting Guide has more information about translating from the Objective-C documentation, which is what Apple expects you to use.
This should work :
set sharedWorkspace to current application's NSWorkspace's sharedWorkspace()
I have an Applescript that runs fine on my Macbook Retina but fails on a Mac Mini.
Both are running MacOS 10.9.2.
After peeling the onion a bit I'm able to reproduce the problem with a one-line Applescript:
tell application "MidiPipe" to activate
On the Mini that throws the error:
An error of type -10810 has occurred.
On the Macbook the MidiPipe application opens.
MidiPipe works normally on the Mini when started from the Finder or from Launchpad.
Google provides no insight into this error.
Well, I found this: http://www.thexlab.com/faqs/error-10810.html and this: http://osxdaily.com/2010/02/09/mac-error-10810/ and this: http://forums.adobe.com/thread/1389805 . At least one of these suggests a RAM problem.
But just to make sure you've tried every weird variation, have you tried the following:
1) using a full path:
tell application "Full:Path:To:MidiPipe.app" --(probably "YourHDName:Applications:MidiPipe.app"?
2) using an actual tell block:
tell application "MidiPipe"--or full path
activate
end tell
3) using the Finder:
tell application "Finder" to open "Full:Path:To:MidiPipe.app"
4) using shell:
do shell script "open /Applications/MidiPipe.app"
?
After looking at the links in CRGreen's answer, it looks like this is likely being caused by the process table being full on the mini. This, in turn, prevents any new applications from opening. According to The X Lab:
Error -10810 is a Launch Services result code indicating an unknown error. One cause of this error is that the Mac® OS X process table is full. When the process table is full, new (not currently running) applications cannot be opened until another running application ends. Programming errors in third-party applications can fill-up the process table, leading to the -10810 error when opening an application.
I would start by restarting the mini to see if that clears the process table, allowing you to to start MidiPipe.
If that doesn't work, you should look at your Activity Monitor to see if there is a specific program filling up your process table.
Could be nothing more than another mysterious grieving crap from Apple.
Today I have faced this myself, first time after using four different Mac Minis as build servers for Continuous Integration of Mobile apps for about two years or so.
My Jenkins runs the osascript from the bash script to build the app.
A few days ago the office experienced the power outage and all Macs went down. After powering them back on I have got this error at osascript execution on one of my Macs.
I have tried just to re-build - with the same result.
First thing I stumbled upon was https://jacobsalmela.com/2014/08/04/infamous-execution-error-error-type-10810-occurred-10810/ , but none of them applied to me.
Then I googled more general 10810 issue occurrences and went through couple of questions here on SO.
Still no luck.
Next I reached to the server via SSH using PuTTY and tried telling Terminal to do the very basic script like
osascript -e 'tell application "Terminal"
activate
tell window 1
do script "counter=0; while true; do if [ \"$counter\" -gt \"10\" ]; then
break; else counter=$((counter + 1)); sleep 1; fi; done; exit;"
end tell
end tell'
This worked fine.
Then I tried to run the whole bash script that Jenkins used to execute. Everything went just perfect and the app was uploaded to HockeyApp as the result.
I came with the thought that the issue is that Jenkins runs it remotely on that Mac and finally I have tried just to re-build again and it magically worked fine this time.
No idea what it was, but since then I have performed three or more builds already and all of them were successful.
Note I haven't changed anything, and my script:
1) never used a full path;
2) always used an actual tell block;
3,4) nothing like that from the accepted answer was ever used.
So... Go away mysterious grieving crap! Go away! :)
In Xcode 4.6, I created a new application based on the "Command Line Tool" project template.
How can I programmatically start another application (.app application bundle) from that "Command Line Tool" app?
There are numerous ways to accomplish this, using Launch Services and or NSWorkspace.
One of the more flexible ways to identity a bundled application is via its bundle identifier (CFBundleIdentifier), which is a string like com.apple.TextEdit. This allows you to identify an application without having to hard-code an assumed path where the application will be found, or by hard-coding the name of the application bundle, both of which a user could easily change. You can use NSWorkspace's launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier: to launch the app. If you don't already know it, you can obtain the bundle identifier of an application bundle by checking its AppName.app/Contents/Info.plist file. Then use the following code:
if (![[NSWorkspace sharedWorkspace]
launchAppWithBundleIdentifier:#"com.apple.TextEdit"
options:NSWorkspaceLaunchDefault
additionalEventParamDescriptor:NULL
launchIdentifier:NULL]) {
NSLog(#"launching app failed!);
}
Important: NSWorkspace is part of the AppKit.framework framework, which is not initially included in the "Command Line Tool" project template. To add it to your project, select the target in the list of targets like shown in the image below, and click the + button to add additional frameworks.
Add both AppKit.framework and Cocoa.framework.
That will result in all 3 being listed in the Link Binary With Libraries step. At that point, you can remove both the Foundation.framework and AppKit.framework from the linking stage, and leave just the Cocoa.framework, like below:
Have you tried "open"? At least in terminal "open" runs files and/or apps.
This problem really puzzles me, since AppleScriptObjC should handle garbage collection just fine on its own.
Anyway, the steps to reproduce this error are:
Create a new Cocoa-AppleScript-Application project
Insert single call to NSMakePoint anywhere in the project's nameAppDelegate.applescript file. The file should now look something like this:
script testAppDelegate
property parent : class "NSObject"
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
set single_point to NSMakePoint(5, 10) of current application
display alert "X-value of point: " & x of single_point
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
display alert "Terminating"
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
Run the application
The above application will launch and display the alert "X-value of point: 5.0" (as expected), but immediately after the alert it will crash with the following EXC_BAD_ACCESS error in the file main.m: main.m error
Thus, somewhere a call is being made to an object that no longer exists. If we profile the application with NSZombies enabled, it confirms that a zombie has been messaged and gives this additional info: zombie info
I've also tried the same thing with NSMakeRange and NSMakeRect instead, and it gives exactly the same result. I suspect every call to a Core Foundation function will crash the application this way. However, if we as an example call stringValue() of a NSTextField, it works just fine.
Putting the call outside of applicationWillFinishLaunching_ does not solve it either. So what am I doing wrong?
I'm using XCode 4.3.3 on OSX Lion 1.7.4
EDIT: After some further research, I realized I do not need to call NSMakePoint, I could just create an AppleScript record like {|x|:0, |y|:0} and it will work just like an NSPoint object. So that solves it, I guess.