Scripts run from Terminal, not executing on dbl click

Forum rules
Before you post please read this

Scripts run from Terminal, not executing on dbl click

Postby nyllix on Mon Sep 03, 2012 8:44 am

One of the features I missed from upgrading to 13 was the "aero-snap" feature. Looking around I found a way to implement this feature: create a script that uses wmctrl to control the window, assign the script to a keyboard shortcut in the Control Center Panel. Here is the really simple 2 line script I am using (snaps window to the left side at half my monitor width):
Code: Select all
#!usr/bin/env bash
wmctrl -r :ACTIVE: -e 0,0,0,960,1200

The 2nd line works great when typed directly into Terminal. As expected, the terminal window jumps and sizes itself like it's supposed to (assuming it isn't already maximized). However, when running the above script via the shortcut... nothing happens. So I ran it out of Terminal and it tells me:
aero-snap_tiling_windows_LEFT: command not found
aero-snap_tiling_windows_LEFT is the name I gave my script. Ya, kinda long, but that doesn't matter. I have definately marked it for execution.

Also, the same sort of thing happens with one of my python scripts. I am using http://inventwithpython.com/chapters/ to learn a bit of python/pygame. I made 3 of the scripts from that site, and 2 work fine, but the 3rd one won't run except by typing it in Terminal. They were all made executable the same way: clicking the button in the permissions tab, and all have the shebang line added. The troubled script is http://inventwithpython.com/chapter19.html and I have only modified it to add a shebang line at the top:
#!usr/bin/env python

Removing this line does not fix the problem with my 3rd file that it errors out when I double click it and choose Run In Terminal. I thought at first that the pygame module somehow wasn't set up correctly. But then why would it work perfectly when typed from Terminal w/ no other changes, and also work perfectly with or without shebang line when run from Terminal? I installed pygame module via Software Manager, and it never reported any errors. It does seem to be the same sort of problem I am having with the aero-snap script above. This 3rd file is in the same directory as 2 other .py files that work fine.

I am stumped. Can anyone help me determine what is wrong?

Thanks!

Running Linux Mint 13 MATE 64
nyllix
Level 1
Level 1
 
Posts: 8
Joined: Wed Jul 11, 2012 10:05 pm

Linux Mint is funded by ads and donations.
 

Re: Scripts run from Terminal, not executing on dbl click

Postby xenopeek on Mon Sep 03, 2012 10:34 am

To run a script that is located in your current directory, you have to make explicit you want to run it from the current directory. So you would instead run it as:
Code: Select all
./aero-snap_tiling_windows_LEFT

When you bind a shortcut to this script, you have to use the full path to the script.

You may also want to look into QuickTile as an alternative: http://ssokolow.com/quicktile/

As for your Python script, you can't give a partial path in the shebang. So it would need to be:
Code: Select all
#!/usr/bin/env python

and not:
Code: Select all
#!usr/bin/env python

Not sure what else is wrong, but that at least is incorrect.
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14807
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Scripts run from Terminal, not executing on dbl click

Postby nyllix on Tue Sep 04, 2012 8:33 am

Well the easy stuff first... the python program that wasn't working - that's a typo. Oops! Just forgot that beginning slash. :P Thanks for catching that!

So I guess the code you gave me for the aero-snap script is to run the script in Terminal, because that works just fine. There are some things though, that just want to make me pull out my hair! For instance, this script would NOT work for me when I set it up in Keyboard Shortcuts in the Control Center. Believe you me I looked it over a hundred times, and the spelling was just fine, everything was looking like it should work (and it did in Terminal). I typed out the absolute path several times, applied and closed (there is no save option), and retyped, re-applied, closed again, but that didn't work. I also tried setting several different keys for the shortcut and that didn't do anything either. Double checked the executable permission was set, both in the GUI and in Terminal (just to be sure!) and none of that helped either. I decided as a last resort to delete the Keyboard Shortcut and add it in again from scratch. Lo and behold, that did the trick, and I just cannot understand what happened, especially since I took great pains to type it in CORRECTLY several times before I deleted it. I guess that is just one of those things where you do some hair pulling a little bit and then move along, cause it works fine now!

THANKS!
nyllix
Level 1
Level 1
 
Posts: 8
Joined: Wed Jul 11, 2012 10:05 pm


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest