Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'use multiple X11 applications' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
use multiple X11 applications
Authored by: jfg on May 16, '03 05:22:30PM

I have been working on doing similar stuff for a while now. I wanted to use one of several X11 applications with one drop application. I chose to do this with an applescript application. Because of the kinds of problems I see in this thread, I use a unix script called "doinshell" that executes the commands in a tcsh or from the terminal so that I have exactly the same environment as if running the command from a terminal. Put this shell script in "~/bin/doinshell" and make it executable "chmod a+x ~/bin/doinshell". (Make sure the terminating character is unix-style). Note that this shell script creates a temporary file in your home directory containing the list of commands called .doinshell0 etc, but it is removed after completing the commands.

#! /bin/sh
usage="Usage: `basename $0` [-h] [-t title] [cmd]"
title=NONE
tflag=0
while :
do
case "$1" in
-h*)
echo "execute commands within a tcsh shell"
echo "[option: within a new Apple terminal]"
echo $usage
echo " -h help"
echo " -t in terminal with specified title"
exit 0;;
-t) tflag=1; shift; title="$1" ;;
*) break ;;
esac
shift
done
# create unique temporary file
for num in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
do
tempfile=~/.doinshell$num
if [ ! -e $tempfile ]
then
break
fi
done
echo "#! /bin/tcsh" > $tempfile

if [ $tflag -eq 1 ]
then
weird=\"\]2\;\\\!\:1\\"
echo "alias settermtitle 'echo -n $weird'" >> $tempfile
echo "settermtitle $title" >> $tempfile
fi

for cmd
do
echo "${cmd}" >> $tempfile
done
echo "rm ${tempfile}" >> $tempfile
chmod +x $tempfile

if [ $tflag -eq 1 ]
then
open -a /Applications/Utilities/Terminal.app/ $tempfile
else
exec $tempfile &
fi


Now save the following applescript (I call it "visual X") as an application selecting the save option "stay open", but not "run only", "startupscreen", or "requires classic".

--this applescript uses my homemade unix script "doinshell"
--which start an application within a tcsh (or terminal)
--this sets the environment the same as if typing the command at a terminal
property launchstr : "~/bin/doinshell "
property bgstr : " > /dev/null 2>&1 & " --need last bit to redirect standard output and error to proceed
property appNameList : {"GhostView", "XView", "ImageMagick", "Gimp"}
property appCmdList : {"/sw/bin/gv", "/sw/bin/xv", "/sw/bin/display", "/sw/bin/gimp"}
property appTermList : {"", "", " -t ImageMagick", ""}

on run
tell application "X11" to activate
end run

on open (fileList)
activate
set numApps to count of appNameList
set xappName to the first item of (choose from list appNameList with prompt "View with X11 application:" default items {"GhostView"})
tell application "X11" to activate
set n to 1 as number
repeat numApps times
if xappName is item n of appNameList then
set xapp to item n of appCmdList
set termstr to item n of appTermList
exit repeat
end if
set n to n + 1
end repeat
repeat with theFile in fileList
tell application "Finder"
set theFolder to container of theFile
set file_name to the name of theFile
set file_ext to the name extension of theFile
end tell
set file_name to "'" & file_name & "'"
set folder_name to theFolder as string
set unix_dir to POSIX path of folder_name
set unix_dir to "'" & unix_dir & "'"
set cdcmd to " \"cd " & unix_dir & "\" " as string
set cmd to "\"" & xapp & " " & file_name & "&\" " as string
set wholecmd to launchstr & termstr & cdcmd & cmd & bgstr
do shell script wholecmd
end repeat
end open


Now you can drop a file or files into the applescript and open in either gv, xv, ImageMagick or gimp. For some reason, I am only able to launch ImageMagick from the terminal so I use the -t option of the "doinshell" script.

Hope someone finds this useful.



[ Reply to This | # ]
use multiple X11 applications
Authored by: jfg on May 16, '03 06:45:41PM

The strange characters that make up the string "weird" did not come out correctly. If you want the correct characters you can cut and paste them from the file "/usr/share/tcsh/examples/aliases"



[ Reply to This | # ]
use multiple X11 applications
Authored by: ssevenup on May 16, '03 07:49:11PM

You need to use the

<pre>
<code>

Code text

...

</code>
</pre>

tags (html format) to preserve the wierd stuff. That's what makes the code stand out in yellow. There should be an FAQ or style guide somewhere here, but I have never found one.

Your mechanism is cool, but it's seems a bit Rube Goldberg ;-)

--MM


---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.



[ Reply to This | # ]