View Full Version : applescript Terminal.app?
the_shrubber
05-15-2002, 09:08 AM
Hi,
Does anyone know how i can find out the applescriptability of an application? Basically some way of checking "yes, this component of the application will respond to an applescript invokation"
I'm trying to write an applescript to change the color of my text in Terminal.app. The reason why i want to do this is so that i can alias ssh and su such that everytime i ssh to a different machine, or that i su to a different user, the color automatically changes and i know i'm either somewhere else or someone else.
For example, i'd alias su to 'read_terminal_colour; change_terminal_colour blue; su [args]; change_terminal_colour default'
But not knowing very much Applescript, i don't know how to start. I mean, tell application "Terminal" to... what? open its Inspector menu and select blue for the "Normal Text" color... something like that.
Help? Thanks!
Craig R. Arko
05-15-2002, 09:21 AM
Many times the only documentation is the AppleScript dictionary of the target application, so run Script Editor and open it up.
Terminal's is pretty small :
Terminal Suite: Terms and Events for controlling the Terminal application
run: Run the Terminal application
quit: Quit the Terminal application
count: Return the number of elements of a particular class within an object
do script: Run a UNIX shell script or command
Class application: The Terminal program {properties about the application}
Class window: A Terminal window {many properties about terminal windows}
So just check it out and then experiment. Mostly it's 'do script' this and 'do script' that. :)
the_shrubber
05-15-2002, 10:53 AM
thanks!
I didn't even know there was such a thing as a dictionary until you answered. this is exceedingly cool. I'll append any answer i come up with to this post.
the_shrubber
05-15-2002, 01:12 PM
Here's what seems to work
~/scripts/termcolour_get.sh
#!/bin/sh
osascript -e 'tell application '\"Terminal\"' to tell the front window to get its normal text color'
~/scripts/termcolour_set.sh
#!/bin/sh
if [ $# -lt 1 ]; then
echo "(termcolor_set) usage: <color>"
exit 1
fi
NEW_COLOR=$*
osascript -e 'tell application "Terminal" to tell its front window to set its normal text color to "'"${NEW_COLOR}"'"'
~/scripts/termcolour_wrap.sh
#!/bin/sh
if [ $# -lt 2 ]; then
echo "(termcolor_wrap) usage: <tmp color> command..."
echo "for example: $0 'light gray' ssh foo@bar.com"
exit 1
fi
NEW_COLOR=$1; shift
OLD_COLOR=`${HOME}/scripts/termcolour_get.sh`
if [ "${OLD_COLOR}" == "unknown" ]; then
echo "sorry! you need to set your terminal to a known colour such as 'light gray'"
exit 1
fi
${HOME}/scripts/termcolour_set.sh ${NEW_COLOR}
$*
${HOME}/scripts/termcolour_set.sh ${OLD_COLOR}
.cshrc
alias decolorterm '${HOME}/scripts/termcolour_set.sh light gray'
alias su '${HOME}/scripts/termcolour_wrap.sh green \su \!*'
alias ssh '${HOME}/scripts/termcolour_wrap.sh yellow \ssh \!*'
decolorterm
Two things i don't like
[list=1]
you have to use colors it has strings for, like "light gray"
you have to set the color using the applescript first (see the cshrc)
[/list=1]
Anyone want to comment? I'm sure there's lots of improvements to be made. Macs make me happy, even if i'm all diehard and UNIX lovin'
Coming up: different colours for different servers!
the_shrubber
05-15-2002, 02:00 PM
(note: this script has been modified for easier updating)
~/scripts/sshcolour.sh
#!/bin/sh
if [ $# -lt 2 ]; then
echo "(sshcolour) usage: <command> <location> <ssh-args>..."
exit 1
fi
DEFAULT_COLOR=red
GENTLE_COLOR='light gray'
SSH_COMMAND=$1; shift
TARGET=$1; shift
SERVER_0_COLOR="yellow"; SERVER_0=blah.bar.edu
SERVER_1_COLOR="brown"; SERVER_1=blah.blah.ac.uk
SERVER_2_COLOR="orange"; SERVER_2=sourceforge.net
SERVER_3_COLOR="white"; SERVER_3=blahblah.blah.fr
SERVER_4_COLOR="purple"; SERVER_4=bal.hl.blah.cn
NUM_SERVERS=5
COLOR=${DEFAULT_COLOR}
c=0; while [ ${c} -lt ${NUM_SERVERS} ]; do
eval server=\$\{SERVER_${c}\}
perl -e 'exit 1 unless q/'${TARGET}'/ =~ /'${server}'/' && eval COLOR=\$\{SERVER_${c}_COLOR\} && break
c=`perl -e 'printf '${c}'+1;'`
done
${HOME}/scripts/termcolour_wrap.sh ${COLOR} ${SSH_COMMAND} $* ${TARGET} && exit 0
${HOME}/scripts/termcolour_set.sh ${GENTLE_COLOR}
exit 1
~/.cshrc
alias ssh '${HOME}/scripts/sshcolour.sh \ssh'
I'm getting all giddy now over the 3 extra seconds of productivity i've saved for all that time spent...
Now can you modify this script to be faster/lighter weight?
anthony11
10-16-2007, 04:23 PM
Good stuff, but where can one find the list of known color names? I thought at first that the "Apple" list in color picker was appropriate, but "light gray" as in your example works yet is not among those in the color picker.
The X11 color db doesn't seem to be in play either.
the_shrubber
10-18-2007, 09:28 AM
Good stuff, but where can one find the list of known color names?
I don't remember. Trial and error?
Do check out the
latest version (http://chronicallyuntied.org/download/colorwrap_2005-09-21.tgz) of it, though. It includes some use of RGB values as well.
hayne
10-18-2007, 10:45 AM
On the subject of AppleScripts to change Terminal colour settings, see: http://www.red-sweater.com/blog/220/random-color-terminal
anthony11
10-18-2007, 05:17 PM
On the subject of AppleScripts to change Terminal colour settings, see: http://www.red-sweater.com/blog/220/random-color-terminal
Looks like a binary :-/
anthony11
10-18-2007, 05:19 PM
I don't remember. Trial and error?
Do check out the
latest version (http://chronicallyuntied.org/download/colorwrap_2005-09-21.tgz) of it, though. It includes some use of RGB values as well.
That domain is "parked" so that URL doesn't work.
maartenvandyck
08-07-2008, 03:17 AM
Guys,
I realy needs some help because I'm a rooky:
I want to automaticly run a script in terminal via applescript to automatically set user rights.
Why?
Whell, I have on my mac two users: user1 and user2. User1 is always logged in, user2 just accesses the mac through ftp to put files on it.
Now,I want to run a php script (as user1), which takes a folder of user2 and automatically resizes every photo that is in the folder.
I did some tests and the conclusion: it doesn't work because user1 hasn't got rights to write in user2 's folder.
If I manually change the rights in finder (user1= admin), it works. But everytime that user2 put some new files in the folder, these files cannot be accessed by user1
So i thought to solve this some way by making an automatic script in terminal to set user rights (chmod or something).
Or does somebody have another solution for my problem.
Note: I placed the php script in the map "sites" of user2, and i access it by surfing with safari to http://localhost/~user2/script.php
the script looks to a folder "photos", which also is located in the Sites folder
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.