I was trying to use a script to open CS:GO with an AppleScript program, but I get the error message:
Handler cannot handle objects of this class -10010
Here's the script:
set myfilepath to "Macintosh HD:Users:Kasper:Desktop:Counter-Strike Global Offensive"
tell application "Finder" to open myfilepath
delay 5
tell application "System Events" to set unixID to unix id of process "csgo_osx"
do shell script ("renice -20 -p " & unixID) password "2306" with administrator privileges
Any ideas why this happens?
Your second line is telling Finder's Open command to open a string. It needs to be given a file or alias. Change that line to:
tell application "Finder" to open file myfilepath
Related
Hello and thanks for your help,
This is driving me crazy! I keep having syntax errors for simple stuff like just opening a file.
I get > Syntax Error - Expected end of line, etc. but found “"”.
What am I doing wrong? It's the same quotes as the ones for Finder...
tell application "Finder"
set theFile to selection
open theFile with application "QuickTime Player"
end tell
Here is the corrected script[1]:
tell application "Finder"
set theFile to selection
open theFile using application file "QuickTime Player" of folder "Applications" of startup disk
end tell
This can be simplified by specifying the application by bundle ID instead of location, in which case Finder will find it for you:
open theFile using application file id "com.apple.QuickTimePlayerX"
Or, if you want to do stuff with the file(s) once they’re opened:
tell application "Finder"
set theFiles to selection as alias list
end tell
if theFiles is {} then error "No files selected."
tell application "QuickTime Player"
activate -- (ensures any "can't open file" error dialogs are visible)
open theFiles
-- do other stuff here
end tell
--
[1] The syntax error is due to the special behavior of with/without parameter labels, which expect to be followed by a single keyword (or comma-separated keywords). AppleScript reads the command as open theFile using application—and since a command can’t be immediately followed by an expression, in this case a literal string, it reports a (frustratingly unhelpful) syntax error.
I'm attempting to set the current desktop picture to an image in the current directory of the script. For example, if my folder structure is:
~/Documents/Scripts/DesktopImageScript/image.jpg
With the script in the same directory, I want to be able to set the desktop image to the image.jpg without directly referring to the folder structure. The code I am currently using to fetch the current directory is:
tell application "System Events" to set app_directory to POSIX path of (container of (path to me))
The issue isn't in that code as I can run the following command with the expected and correct results:
do shell script "echo " & app_directory
I believe the issue is in the code I'm using to set the desktop image:
tell application "Finder"
set desktop picture to POSIX file (quoted form of POSIX path of (app_directory & "/image.jpg"))
end tell
The error I receive when I try to run the script is:
error "Finder got an error: AppleEvent handler failed." number -10000
Not really sure what could be causing the error or how to fix it. Any help is appreciated. The full script is below:
tell application "System Events" to set app_directory to POSIX path of (container of (path to me))
tell application "Finder"
set desktop picture to POSIX file (quoted form of POSIX path of (app_directory & "/image.jpg"))
end tell
Solved by using code from another answer on StackOverflow.
tell application "System Events"
set theDesktops to a reference to every desktop
repeat with x from 1 to (count theDesktops)
set picture of item x of the theDesktops to app_directory & "/image.jpg"
end repeat
end tell
I'm trying to write a script that will get the selected file's path and type it into terminal for me. I'm new to scripting so this is all I have so far - the mistakes will be nice and obvious!
set filepath to (currently selected file's path, or drag-and-dropped file...?)
activate application "Terminal"
tell application "System Events" to keystroke "./aerender -project " + "'$filepath'"
tell application "System Events" to keystroke return**
I know that's totally wrong but hopefully it give the idea of what I'm trying to do.
Thanks in advance!
You can script Terminal directly... no need for UI scripting.
tell application "Finder" to set filePath to POSIX path of file (selection as string)
set filePath to quoted form of filePath
tell application "Terminal"
activate
set currentTab to do script ("./aerender -project " & filePath)
end tell
I would like to know how to get the current location of the current session in iTerm using Applescript.
I have tried all sorts of things. The dictionary is very difficult for me to understand.
Here is my latest attempt
tell application "iTerm"
tell the current session of current terminal
set theSelection to attachment file name
display dialog theSelection
end tell
end tell
And the error this produces is:
error "iTerm got an error: Can’t get file name of current session of current terminal." number -1728 from file name of current session of current terminal
I just want the location the iTerm session is currently in: /Users/SuperCoolGuy/Desktop
This is ugly...
tell application "iTerm"
if not (exists terminal 1) then reopen
set mySession to current terminal's current session
tell mySession
write text "pwd"
set sessionContents to it's text
end tell
end tell
set myPath to paragraph -2 of (do shell script "grep . <<< " & quoted form of sessionContents)
If somebody stumbles upon this question, there's another option now with Shell integration. With it you can access the path in AppleScript using the iTerm defined variable session.path:
activate application "iTerm"
tell application "iTerm"
tell current session of current window
set myTerm to (variable named "session.path")
write text "echo this is the current path: " & myTerm
end tell
end tell
That information isn't currently available through iTerm's AppleScript interface. The only exposed properties of the session object having to do with what's running in it (as opposed to its visual appearance) are contents and tty, and those aren't what you're looking for here.
How would I go about opening a file from within an applescript application? I'd place it in /Contents/Resources of my applescript application. What I want to know is what I would tell the actual script to do?
To get the path to your application, use the path to me command and build a path to your resource. Then, you can use Finder to open the file with the default program, or you can tell a specific program to open the file.
set filepath to (path to me as string) & "Contents:Resources:file.ext"
tell application "Finder"
open alias filepath
end tell
--OR
tell application "Microsoft Word"
open alias filepath
end tell