I've written a Mac app that isn't scriptable (yet), and I'd like to run it with Applescript. Either of the following scripts get "An error of type-10660 has occurred.". After hours of searching, I haven't found a solution, or an explanation of the error.
if exists application "RotorDCU" then
display dialog "Found." buttons {"OK"}
else
display dialog "Not found." buttons {"OK"}
end if
tell application "RotorDCU"
activate
end tell
Error -10660 is a Launch Services error, explained in the interface file LSInfo.h:
The app cannot be run when inside a Trash folder
Is RotorDCU in the Trash, perchance?
Related
I was getting this error with a script wrote to on AirPlay. The script ran as expected as I was creating it in the Automator App. When I tried to run it as a service from another app, I received the error message above.
tell application "System Events"
tell process "SystemUIServer"
click (menu bar item 1 of menu bar 1 whose description contains "Displays")
click menu item "Family Room Apple TV" of menu 1 of result
delay 1
click (menu bar item 1 of menu bar 1 whose description contains "Displays")
click menu item "Use As Separate Display" of menu 1 of result
delay 5
end tell
end tell
Works fine in automator. When I try to run it as a service: “The action ”Run AppleScript“ encountered an error."
I read about another user who was having a similar problem with another script. The solution to his problem was to grant accessibility permission from the app he was using the service. I remembered that as I was creating the script in automated i had to grant automated permission. So, I granted permission to the Finder App. Now it runs fine as a service from Finder. But I want this service to be able to run ANY time no matter what app is active. I certainly don't want to have to give permission to EVERY app on my MAC. I'm sure I am also missing something simple and dumb. Any Ideas?
I am still new to programing but I have a AppleScript Error that I need help with.
I am creating a prank using AppleScript but this error message showed up when I tried to compress the file.
Expected “else”, etc. but found end of script.
Here is my code. Please help me fix this! Thanks!
display dialog "Virus Detected" buttons {"Shut Down", "Crash CPU"} default button 2
if the button returned of the result is "Shut Down" then
beep 10
display dialog "Virus Downloaded. Commencing Virus Deletion Process. Shutting Down"
say "Virus Deletion Process FAILED. Virus Downloaded. Shut Down Has Been Overrided"
display dialog "All Systems Has Been Hacked. Computer Is Now Overloading"
display dialog "Passwords Have Been Hacked" buttons {"Abort"}
if the button returned of the result is "Abort" then
display dialog "About Has Been Overrided. Passwords Are Now Uploading" buttons {"Cancel"}
if the button returned of the result is "Cancel" then
display dialog "Overrided. Uploading Complete. Deleting ALL Files From Main Data Base."
say "Deletion Complete"
display dialog "Shutting Down"
tell application "Finder" to shut down
else
beep 10
display dialog "Virus Downloaded Successfully. Computer Has Been Hacked"
say "Virus Has Hacked Into The Motherboard"
display dialog "Deleting All Files. Restoring From Backup"
say "No Backups Were Found"
display dialog "Deleting ALL Data. Computer Is Now Crashing. Shutting Down"
tell application "Finder" to shut down
end if
In line 8 and 10 there are two if clauses.
Each of them must be balanced with an end if (before the else)
I am having issues with applescript, where whenever I open an applescript file (either in AppleScript Editor or in Automator) it will automatically open any programs mentioned in a tell statement/block. Most of these tell blocks are only reachable through conditionals and I would like to find a way to stop applescript's default behavior of opening all mentioned applications.
This is basically what I am doing:
if currentApplication is "Application 1" then
tell application "Application 1"
do stuff
end tell
else if currentApplication is "Application 2" then
tell application "Application 2"
do stuff
end tell
end if
Unfortunately, whenever I open this script it will open both "Application 1" and "Application 2" if they are not open yet, even though it should only get to the tell statements if one of the applications is open. The way I get the current application is not really relevant, even if my 'if' statements were "if false" and I cut out the method that gets the "current" (or closest) application, the applications will still be opened along with the applescript.
If you just run a compiled script, an application will only be launched if AppleScript needs to send it a command, but if you open the script in a script editor, all of the applications referenced in the script will be launched in order to get their custom terminology - see the AppleScript Release Notes.
I wrote an Service using Apple's Automator. The first action is an "Ask for Text" action. However, when I trigger the shortcut to initiate the service, the modal asking for text pops up, but it does not have focus. I have to use the mouse to click on it.
Is there any way to have automator open this window with the focus on the text input?
Add some applescript to the top of your workflow with the following code. Just replace myapp with your app name
tell application "myapp"
activate
end tell
This is a sort-of, works-for-me, partial answer; instead of using the Ask for text action, I just used an applescript within my automator app (instead of the Ask..action, I used the "Run applescript" action). it looks like this:
on run {input, parameters}
set x to the text returned of (display dialog "Enter a version number" default answer "1134" buttons {"OK"} default button 1)
return x
end run
My lil' automator application was to help me enter version numbers for tickets; using the mouse makes my hand hurt. The applescript dialogs seem to have focus properly, so enjoy! Let us know how you do!
I appreciate that there are already questions on this topic, but having read the ones I can find (particularly this one: Tell AppleScript To Build XCode Project), they all seem to be a couple of years old and the answers do not seem to apply to the current version of Xcode.
Similarly to the linked question, I am attempting to automate opening an Xcode project, building it and then running the app in the iPhone Simulator (v4.3). The project in question is the Selenium project's iPhoneDriver (see here for details: http://code.google.com/p/selenium/wiki/IPhoneDriver)
Based on the answer in the other question, I have written the following script:
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
Unfortunately, when I run this I get the following:
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
If I run just the open command, Xcode opens the project without issue. But as soon as I include the rest of the script the Xcode icon in the dock bounces, but that's all I get, apart from the above from the AppleScript Editor.
Can anybody advise what I'm doing wrong? This is the first time I've used AppleScript or Xcode, so I'm struggling to diagnose the problem.
I've tried looking at the Xcode AppleScript Dictionary, but without worked examples I can't quite determine the syntax I need.
Thanks in advance for any help!
Using a mix of AppleScript, and command line tool (xcodebuild), I came up with this:
-- This script will clean, build then run the project at the path below.
-- You will need to slightly modify this script if you have more than one xcodeproject at this path
set pathOfXcodeProject to "/Users/<username>/Documents/Code/Selenium/iphone/iWebDriver.xcodeproj"
-- End of configuration
do shell script "cd " & pathOfXcodeProject & " && /usr/bin/xcodebuild clean build "
tell application "Xcode"
open pathOfXcodeProject
activate
end tell
tell application "System Events"
get system attribute "sysv"
if result is greater than or equal to 4144 then -- Mac OS X 10.3.0
if UI elements enabled then
tell application process "Xcode"
click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
end tell
else
beep
display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop
if button returned of result is "OK" then
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
end tell
end if
end if
else
beep
display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"
end if
end tell
Let me know if this works for you.
I tested it against Xcode 4.2.1 on Lion, with an iPhone project.
If you're ok with Xcode coming to the foreground, I would use this instead:
tell application "Xcode"
activate
open "/Users/<username>/Documents/Code/Selenium/iphone/iWebDriver.xcodeproj"
end tell
tell application "System Events"
key code 15 using {command down}
end tell
Although I vote and cheer the above AppleScript, which is really good (and also works…) being all professional, taking care of old versions, and extreme cases etc. The script suggested by the question should have worked in the first place.
The reason it doesn't work is broken Xcode scriptability. Not only "clean" doesn't work. Most everything I tried to do with the internal object model of Xcode doesn't work.
AppleScript architecture (OSA) requires an application to expose a "human understandable" object graph that AppleScripts can reference. In Xcode it may look like:
tell target "my library" of project "my project" of workspace "my workspace" to clean.
or
tell application "Xcode" to close all projects whose name contains "Lib"
User-Interface scripting is the last resort of the scripter when application scriptability is poor. Because the UI hierarchy is standard in nature, and its scriptability is free from Cocoa, it most always work.