Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Auto run a script logging into Openbox +others ...

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
Deb-fan
Posts: 1047
Joined: 2012-08-14 12:27
Been thanked: 4 times

Auto run a script logging into Openbox +others ...

#1 Post by Deb-fan »

Not really sure this is even worthy of a how-to but why not ? In the case of Openbox and many other WM's = windows managers there are provisions to automatically start apps or whatever, in the case of Openbox, this is found at /home/username/.config/openbox/autostart ... Mentioned someone can add things they wish to autostart in this and it'll get run to launch those when the system starts-up. Lately find myself on ways to run scripts kick and yep, running one via the use of the Openbox autostart file works too.

Okay, I've got a directory named .bin in my users home directory which I sometimes use for the purpose of stashing user scripts and I made one with the following contents, it's named test.sh

Code: Select all

#!/bin/bash
/usr/bin/leafpad /home/myusername/Blahblah/test.txt
What it does is launch leafpad (a text editor I use, of course you can use any editor you prefer there) and has it open the text file I want at that location, which would be as shown above, a file named test.txt kept in a directory called Blahblah in my users home directory. Okay so now we've got our script, make it executable "chmod +x ~/.bin/test.sh" next up, time to add what's needed to the Openbox autostart file to run the script. At the bottom of the file I added ...

Code: Select all

# Running a damn bash script in .bin. Yep works ...
bash -c "/home/myusername/.bin/test.sh" &
This works, as would ...

Code: Select all

/bin/bash /home/myusername/.bin/test.sh &
Or

Code: Select all

bash -c "~/.bin/test.sh" &
Actual line I used is/was, which also works fine too. Currently commented out in the autostart file.

Code: Select all

bash -c  ".bin/test.sh" &
Lastly I need to create a file named test.txt in the appropriate location and add some text contents to it for demonstration purposes. Noted in another thread using this ~/ is the same thing as typing out /home/yourusername and of course use the correct file path to the script you're wanting to run there. If I source that file ie: type "source .config/openbox/autostart" in terminal, it runs the autostart file again ... Up pops the file I wanted in the leafpad text editor as it will whenever I boot into Openbox until I remove or comment out the line which runs the script in it.

More random useful stuff, some useful Openbox terminal cmds, in particular just to be overly anal and confirm the syntax of a given line there above worked as expected, could've just sourced the file, yep ... you can use a . (which is shorthand for typing source) /path/to/autostart or script, kind of dirty, worked well enough for this junk though, however another thing which can be good to know is the "openbox --exit" command in a terminal, when used that's what it does, it exits the openbox session. I have my system setup to automatically log my user in so when I enter that cmd, kills the ongoing openbox session but my OS turns right around, logs me back in and during this process my Openbox autostart file gets ran(sourced)each time. Same is going to happen if you were using a display manager set to autologin your user. Other similar Openbox cmds, "openbox --restart" and "openbox --reconfigure" can come in handy too.

Well that's it, yeppers pretty much same approach is sure to work in Fluxbox or others also. Good enough for running user scripts, whereas would be apt to go with something else for system scripts, altering system files or running cmds which require priv's etc. Still this could inspire someone to do something interesting with their OB and/or other windows managers. Also surely any good desktop should, is bound to have similar provisions for such things too. Though there you have it, do something useful and-or cool with this stuff. :D
Most powerful FREE tech-support tool on the planet * HERE. *

Deb-fan
Posts: 1047
Joined: 2012-08-14 12:27
Been thanked: 4 times

Re: Auto run a script logging into Openbox +others ...

#2 Post by Deb-fan »

Lol ... yep, another method of doing this type of thing, certainly applies to Openbox and others, though this is more so desktop or windows manager agnostic as it's used on so many things should simply work. You will however have to fiddle around with the script contents based on what you're trying to do, in this case I'm using a bash script already shown in another tute (the one on bash aliases)along these lines, that's still ~/.bin/edit.sh and it has the following content still also.

Code: Select all

#!/bin/bash
/usr/bin/leafpad /mnt/data/.directoryname/.blahblah/newstufftosave/patches &exit
Which still does the same thing when I run the script, opens the file in the path shown above, a text file named patches with leafpad for me. Again, make the-your script executable with "chmod +x /path/to/scriptname.sh". Now going to run this puppy by using a .desktop file, you can put them into the /home/yourusername/.config/autostart directory. I created one named script.desktop then added the following contents to it.

Code: Select all

[Desktop Entry]
Name=script.desktop
Comment=
Exec=/home/myusername/.bin/edit.sh
Terminal=false
Type=Application
Note: That I gave it the same name as the .desktop file I created, do that, these need to also be made executable with "chmod +x" too. Yeppers when I logged out/in, wham this .desktop file ran the script and it did what I was wanting as outlined above. I am using this to launch a graphical application = leafpad, so this is good enough for doing that. Again ... this is appropriate for autostarting applications when a user logs in and for unprivileged stuff along those lines. However again TONS of GUI's will run those .desktop files so it's pretty versatile. Such files certainly work in Openbox, also in Fluxbox, no doubt PLENTY of others.

By way of further example, this is the contents of a tint2.desktop file I've used in both Openbox and Fluxbox, very likely others I just don't remember to launch the tint2 panel at login in both those WM's w/o using their autostart files .... Name of the thing = tint2.desktop, as noted it needs to be made executable and yep, it's put into ~/.config/autostart you can create that directory if it doesn't exist on your system.

Code: Select all

[Desktop Entry]
Name=tint2.desktop
Type=Application
Exec=/usr/bin/tint2
Terminal=false

Crosslink to bash alias how-to, http://forums.debian.net/viewtopic.php?f=16&t=147296

Alrighty, that's a wrap. :)
Most powerful FREE tech-support tool on the planet * HERE. *

Post Reply