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


Click here to return to the 'Create a dockable X11 application' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a dockable X11 application
Authored by: dafdaf on Mar 08, '04 12:37:03PM

Nice hint. I just created a tiny little app to launch (fink-) gimp for me:

run application "X11"
do shell script "cd /sw/bin/; export DISPLAY=:0.0; ./gimp & > /dev/null 2>&1 &"
tell application "X11" to activate

After saving as application, assigning an icon is just a matter of copying the appropriate icon to the info-window of the app.

But one annoyance I've found: After creating the said Gimp-icon, I was unable to open graphic-files by dragging them to the dock icon. I don't know if that can be changed by setting parameters in the applescript or if that's just impossible with X11-apps.

Maybe someone with mor applescript-skills can point me to the manual/faq entry...



[ Reply to This | # ]
Create a dockable X11 application
Authored by: glusk on Mar 08, '04 02:01:41PM
Here's a kludge of many examples (some from MacOSXhints) that I use to start up GIMP. Thanks to the people submitted hints for me to copy from. This applescript can be saved as an application bundle and have a .icns associated with it. You can find a copy at: http://homepage.mac.com/glusk/FileSharing3.html If anyone has any improvements, please share.

tell application "X11" to activate

set filecount to 0

if filecount < 1 then
	set isRunning to 0
	try
		set isRunning to do shell script "/bin/ps -auxww | /usr/bin/grep gimp | /usr/bin/grep -vc grep"
	end try
	if isRunning is 0 then
		do shell script "export DISPLAY=0:0; /sw/bin/gimp > /dev/null 2>&1 &"
	end if
end if

on open filelist
	tell application "X11" to activate
	
	repeat with i in filelist
		set filecount to 1
		set filename to do shell script 
			"perl -e \"print quotemeta ('" & POSIX path of i & "');\""
		
		set isRunning to 0
		try
			set isRunning to do shell script "/bin/ps -auxww | /usr/bin/grep gimp | /usr/bin/grep -vc grep"
		end try
		if isRunning is not 0 then
			do shell script "export DISPLAY=0:0; /sw/bin/gimp-remote " & filename & " > /dev/null 2>&1 &"
		else
			do shell script "export DISPLAY=0:0; /sw/bin/gimp " & filename & " > /dev/null 2>&1 &"
		end if
	end repeat
	
end open



[ Reply to This | # ]
Create a dockable X11 application
Authored by: dafdaf on Mar 08, '04 06:42:34PM
*very* nice script, indeed. - Works like a charm !
By adding the following lines to the bottom of the script, it's possible to quit Gimp via the dock as well:
on quit
	do shell script "/bin/ps -x | /usr/bin/grep gimp | /usr/bin/grep -v grep | /sw/bin/awk '{print $1}' | xargs kill"
	continue quit
end quit

And as ncrocker pointed out: It's important to select 'stay open' when saving the script.

[ Reply to This | # ]
Create a dockable X11 application
Authored by: Eponymous on Mar 09, '04 09:51:30AM
A nice addition would be to have the script quit itself when you close Gimp. The bit below is just modified from the original and checks for "gimp" in running processes, then quits if that isn't found. Note that it ignores "MacGimp" which is in the name of my version of the script; you'll want to get rid of that part if you have a name that doesn't include "gimp".

I can't get it to quit by putting the "tell me to quit" within the repeat loop, which seems odd to me.

This also breaks the "on quit" bit posted earlier, presumably because the script is looping through the repeat and can't look for a "quit" message. Should be a way around that, no?


repeat
	set isRunning to 0
	try
		set isRunning to do shell script "/bin/ps -auxww | /usr/bin/grep gimp | /usr/bin/grep -v MacGimp | /usr/bin/grep -vc grep"
	end try
	if isRunning is 0 then
		exit repeat
	end if
	delay 10
end repeat

tell me to quit


[ Reply to This | # ]
Create a dockable X11 application
Authored by: ncrocker on Mar 08, '04 06:00:31PM

The script that glusk says to save as an application bundle should let you "open graphic-files by dragging them to the dock icon" if you select the "stay open" option when you save the script. I haven't tried it myself, but it seems to have the magic ingredient for a script application which lets the user open files by dropping them onto the dock icon: an "open" subroutine (a.k.a. an "open" handler in Applescript terminology), which is given by the block of code bracketed by the lines "on open filelist" and "end open"



[ Reply to This | # ]