Scripts --- homemade helpers !!


Abarbarian

Acruncher
Joined
Sep 30, 2005
Messages
10,375
Reaction score
911
Personalising or customising how your pc looks or operates is one of the attractions of being a penguinista. Taking control and making your pc perform as you want can be accomplished with simple scripts.
Learning how to use bash or python etc etc is a daunting task for most folk. Luckily there are plenty of script surfers out there on the net eager to share their creations. The trouble is finding them and quite often understanding how they are made and how you can alter them to suit you.
So in this thread I will try to post scripts that are hopefully useful and are either pretty self explanatory or contain clear and understandable instructions.

Here we go with the first one.

Build a custom system tray indicator using Python

"System Tray icons are still considered to be an amazing functionality today. By just right-clicking on the icon, and then selecting which actions you would like to take, you may ease your life a lot and save many unnecessary clicks on daily basis.

When talking about useful system tray icons, examples like Skype, Dropbox and VLC do come to mind:



However, system tray icons can actually be quite a lot more useful; By simply building one yourself for your own needs. In this tutorial, we’ll explain how to do that for you in very simple steps."

:cool:
 

Ian

Administrator
Joined
Feb 23, 2002
Messages
18,908
Reaction score
958
I've got a few Python scripts on mini servers (to do things like reconnect wifi if it drops, or run patch updates etc...) but they're all very basic things so far. However, I've been using PowerShell in Windows quite a lot recently and I'm pleasantly surprised at how powerful it is. It took me a while to get my head around using it, but I'm a total convert now - it's so much more powerful than the old batch file scripting that I used so much.

On Linux, are scripts like this fairly release agnostic? i.e. would it run on Ubuntu and Fedora with the same code? The example on that link does (with a slightly different install) - is that generally the case for any Python script that interfaces with the GUI?
 

Abarbarian

Acruncher
Joined
Sep 30, 2005
Messages
10,375
Reaction score
911
I've got a few Python scripts on mini servers (to do things like reconnect wifi if it drops, or run patch updates etc...) but they're all very basic things so far. However, I've been using PowerShell in Windows quite a lot recently and I'm pleasantly surprised at how powerful it is. It took me a while to get my head around using it, but I'm a total convert now - it's so much more powerful than the old batch file scripting that I used so much.

On Linux, are scripts like this fairly release agnostic? i.e. would it run on Ubuntu and Fedora with the same code? The example on that link does (with a slightly different install) - is that generally the case for any Python script that interfaces with the GUI?
As long as you have the correct version of Python plus all the dependencies needed by a program then it should run on almost any linux as far as I know. Same goes for Bash scripts which also may run if you are running zsh or fish, I think.
If you are running Python 2 and you find a Python 3 script you may be able to get it to run by simply replacing 2 with 3 etc etc .
I am not very up on scripts but I have made a couple to help out with maintenence on my set up.
It is great when you find or create a small script that does in a click or two what used to take half a dozen clicks.

:nod:
 
  • Like
Reactions: Ian

Abarbarian

Acruncher
Joined
Sep 30, 2005
Messages
10,375
Reaction score
911
So you made a script to automate a task, and set it to run. How do you know that it will, keep on running or exit cleanly ? Simple , you TRAP the little blighter right form the start.
Using Trap to Exit Bash Scripts Cleanly

We have all been there, you write a bash script that creates some temporary files and/or directories for processing some information. You complete your script with some basic testing and all is well. You set your cron job to run the script every day at noon. Six days later you realize that the script has been exiting prematurely and leaving a bunch of trash files in the file system. Or worse, potentially sensitive data is left unprotected. Enter the trap command.

The above scenario is a bit dramatic, but not completely ridiculous. If you are automating tasks with bash scripts you will eventually run into a premature exit. Either as the result of an error, a change in the environment, or an unanticipated user action. Creating scripts that deal with this scenario is imperative to keeping a clean and secure system.
So remember when bashing a penguin remember to trap it first.

:D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top