I am trying to automate a python script with a keyboard shortcut. To do this, I am using the mac automator. In this, it runs this applescript:
on run {input, parameters}
do shell script "python /Users/evettsam000/Desktop/myKeys.py"
return input
end run
When I run it, it makes it to the python file, which starts by importing time, and then importing pyautogui. But there's an error when I run it from the automator, saying there's no module called pyautogui. However, when I run the python script by itself, it works. Is there any applescript command I can use to help this import? Thanks!
Related
I'm currently pulling my hair out trying to make an apple script execute a shell script / Unix executable, so that I can drag it into the dock. I don't have much experience with AS, so this is propably an easy fix for many of you guys.
Here's the whole script:
to run
do shell script "/Users/MyUserName/Documents/cmus/2.7.1_1/bin/cmus"
end run
Cmus is a terminal music program that is a Unix executable.
When I try to run it, I get this error message:
error "Error opening terminal: unknown." number 1
What is the problem? Pls help...
I am guessing your program is curses based and needs a Terminal window, so try this:
to run
tell application "Terminal"
do script "/Users/MyUserName/Documents/cmus/2.7.1_1/bin/cmus"
end tell
end run
#TheUnderBrony don't use do shell script but use do script. do shell script is part of the standard addition.osax which open an shell in the background do script is part of the terminal which will execute the string in a terminal window.- dj bazzie wazzie
This solved my problem, thank you! But Only one slight problem is left: The terminal starts and opens the program, but it opens it in the background, aka, I need to click on the terminal icon to show the window. Do I need to activate the window? If so, how? But already thanks a bunch :)
I am new to applescript and command line tools.
I installed a command line tool to control the brightness of the iMac in Terminal. I installed the following:
https://github.com/nriley/brightness
After installing, I noticed a new exec file in /usr/local/bin/ called "brightness".
The Internet told me, that applescript only knows the command lines found in /bin/sh. "brightness" is not found there, and I can't copy the exec file to this directory. So it makes sense, that I get the error "sh: brightness: command not found", when executing the following applescript:
do shell script "brightness 0.7"
Now the big question, what do I have to do in order to get the shell command working?
In Terminal, the command works fine. I know I could do the following:
tell application "Terminal"
activate
end tell
tell application "System Events"
keystroke "brightness 0.7"
keystroke return
end tell
But this always makes the terminal window active, and I want to run the command silently.
I am glad for detailed instructions. I searched the internet for days, but hey, I am a beginner.
Provide the full path
do shell script "/usr/local/bin/brightness 0.7"
This might be a bit of a dumb question as I'm new to AppleScript, but I'm trying to run a very simple shell script in terminal using AppleScript. The code I'm currently using is:
tell application "Terminal"
do script "videoLoop"
end tell
but I keep getting the error
-bash: fork: Resource temporarily unavailable
Could I also just type "videoLoop.sh" into terminal using AppleScript?
Any help would be appreciated
If you need it to open a terminal window use something like this:
tell application "Terminal"
do script "/Users/youruser/testdir/hello.sh"
end tell
Else, if you just want it to run the script do something like this:
do shell script "/Users/youruser/testdir/hello.sh"
You need the full path, and your script needs execute permissions.
My examples just echo the standard Hello World text but the same should work for most other scripts provided they're written properly.
I am using AppleScript to launch a certain python script. This python script uses arguments. I know how to use do script to launch commands but this time I just want to have python myscript.py ready. After that I would type my own argument and hit RETURN.
I don't know how to put the text in Terminal. Arguments will be different everytime I want to use the script, otherwise I would just use do script.
This will type your command into the current active terminal window:
tell application "Terminal" to activate
tell application "System Events" to keystroke "python myscript.py "
If you need to select which terminal window, then there will be a bit more work to do.
I know there is a Terminal plugin for quicksilver but I would invoke terminal commands which basically just runs in the background and never popups a terminal window. is that possible?
UPDATE:
I have the following code in my applescript but its giving me an error:
do shell script "/path/to/shell.sh blah"
error:
curses.setupterm()
_curses.error: setupterm: could not find terminfo database
In Quicksilver you can use the action "Run Command in Shell", which is part of the "Terminal Module". The command is run without showing a window. Search on the quoted terms and you'll find some examples.
Applescript is the simple solution, see:
http://developer.apple.com/library/mac/#technotes/tn2002/tn2065.html
Sample:
do shell script "ifconfig"
do shell script "ifconfig" user name "Anne" password "p#ssw0rd" with administrator privileges
Automator can also run shell scripts in the background.
If you are familiar with XCode, you can use NSTask with Objective-C.
Hold on a sec, is your shell script a bash shell script? In your first line do you have:
#!/bin/bash
If not, add that line to your script.
Also instead of just
do shell script "/path/to/yourscript.sh"
consider this:
do shell script "/bin/bash /path/to/yourscript.sh"