Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 30 Sep 2016, 06:10
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
How to Make a Clickable Script
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [12 Posts]  
Author Message
rcrsn51


Joined: 05 Sep 2006
Posts: 10984
Location: Stratford, Ontario

PostPosted: Sun 29 Aug 2010, 12:43    Post subject:  How to Make a Clickable Script  

You may have scripts that you use regularly, but must open a terminal window to run them. Here is a simple method for making a script clickable. You can then put a shortcut to the script on your desktop.

Just place the following three lines at the top of the script (without any blank lines):
Code:
#!/bin/sh
tail -n +4 $0  > /tmp/script.txt
exec rxvt -e sh /tmp/script.txt

To leave the terminal window open when the script is done, add this line to the end:
Code:
read

Here is an example. When I'm working with flash drives, I like to run the sync command regularly to ensure that data has been written out to the device. So I made a script called "mysync" and put it in /root/my-applications/bin. I then made a desktop shortcut by dragging the script onto the desktop. That way, I can see the sync command running and I know when it's done.

Code:
#!/bin/sh
tail -n +4 $0 > /tmp/script.txt
exec rxvt -e sh /tmp/script.txt
echo Syncing...
sync

Last edited by rcrsn51 on Sat 02 Feb 2013, 10:48; edited 5 times in total
Back to top
View user's profile Send private message 
abushcrafter


Joined: 30 Oct 2009
Posts: 1438
Location: England

PostPosted: Sun 29 Aug 2010, 17:46    Post subject:  

Thanks.
_________________
adobe flash is rubbish!
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
Back to top
View user's profile Send private message Visit poster's website 
abushcrafter


Joined: 30 Oct 2009
Posts: 1438
Location: England

PostPosted: Tue 31 Aug 2010, 05:21    Post subject:  

You need the 2 main commands to be on the same line with "&&" in-between. Other wise the exec command ends up in the tmp file. So it ends up in a loop where it keeps running more copy's of it self till it crashes your OS from using up all of your ram Sad.
Code:
cat $0 | tail -n +4 > "/tmp/download_magatune_song-of-the-today_tmp.sh" && exec rxvt -e sh "/tmp/download_magatune_song-of-the-today_tmp.sh"


I also added a rm command to delete the tmp file at the end of the script.

_________________
adobe flash is rubbish!
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
Back to top
View user's profile Send private message Visit poster's website 
rcrsn51


Joined: 05 Sep 2006
Posts: 10984
Location: Stratford, Ontario

PostPosted: Tue 31 Aug 2010, 05:40    Post subject:  

Make sure that the first three lines of your script are as shown.

Then the "tail -n +4" copies everything starting at line 4 into the temp file.
Back to top
View user's profile Send private message 
abushcrafter


Joined: 30 Oct 2009
Posts: 1438
Location: England

PostPosted: Tue 31 Aug 2010, 06:11    Post subject:  

rcrsn51 wrote:
Make sure that the first three lines of your script are as shown.

Then the "tail -n +4" copies everything starting at line 4 into the temp file.
Arrr... I get it now. I had a new line after "#!/bin/sh".
_________________
adobe flash is rubbish!
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
Back to top
View user's profile Send private message Visit poster's website 
rcrsn51


Joined: 05 Sep 2006
Posts: 10984
Location: Stratford, Ontario

PostPosted: Tue 31 Aug 2010, 06:29    Post subject:  

abushcrafter wrote:
I had a new line after "#!/bin/sh".

That will do it.

Also, you don't need to delete the script afterward. The /tmp folder is automatically erased.
Back to top
View user's profile Send private message 
abushcrafter


Joined: 30 Oct 2009
Posts: 1438
Location: England

PostPosted: Tue 31 Aug 2010, 06:30    Post subject:  

rcrsn51 wrote:
abushcrafter wrote:
I had a new line after "#!/bin/sh".

That will do it.

Also, you don't need to delete the script afterward. The /tmp folder is automatically erased.
Oh.
_________________
adobe flash is rubbish!
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
Back to top
View user's profile Send private message Visit poster's website 
steve_s


Joined: 26 May 2008
Posts: 1575
Location: Austin, TX, USA

PostPosted: Tue 31 Aug 2010, 07:28    Post subject:  

Thanks for the script tips...keep 'em coming! this is very useful stuff and very appreciated...
Back to top
View user's profile Send private message Visit poster's website 
piratesmack


Joined: 16 Sep 2009
Posts: 100

PostPosted: Tue 31 Aug 2010, 18:23    Post subject:  

Yes, thanks for the tip.

I modified slightly so the script doesn't have to start at exactly 4 lines
Code:

#!/bin/sh

# figure out which line the script starts at
LINE=$(awk '/^START/ { print NR + 1 }' $0)
tail -n+$LINE $0 > /tmp/myscript.txt
exec rxvt -e sh /tmp/myscript.txt

START # script starts after this line
echo "Hello, world!"
read
Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 4160
Location: New Zealand

PostPosted: Sun 10 Apr 2016, 16:51    Post subject: Re: How to Make a Clickable Script  

rcrsn51 wrote:
Here is an example. When I'm working with flash drives, I like to run the sync command regularly to ensure that data has been written out to the device. So I made a script called "mysync" and put it in /root/my-applications/bin. I then made a desktop shortcut by dragging the script onto the desktop. That way, I can see the sync command running and I know when it's done.

Code:
#!/bin/sh
tail -n +4 $0 > /tmp/script.txt
exec rxvt -e sh /tmp/script.txt
echo Syncing...
sync
Hi rcrsn51 - I just did some brief testing with this and the terminal disappeared immediately so I was unable to see anything that was happening. Is that normal, and merely an indication that there was no data to write out?
EDIT : Further testing with larger files and a slow usb stick suggets yes, the terminal disappears as soon as the sync is finished. Excellent.

Quote:
To leave the terminal window open when the script is done, add this line to the end:
Code:
read
I tried appending read as the last line but then the terminal just stayed open but giving no indication of sync having ended as shown here:
sync_hang.jpg
 Description   
 Filesize   31.95 KB
 Viewed   201 Time(s)

sync_hang.jpg

Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 4160
Location: New Zealand

PostPosted: Sun 10 Apr 2016, 17:06    Post subject:  

EDIT : I tried adding an extra line to the script as follows:
Code:
#!/bin/sh
tail -n +4 $0 > /tmp/script.txt
exec rxvt -e sh /tmp/script.txt
echo Syncing...
sync
echo Sync complete.
read

and the outcome seems to work for me. I know when the sync is still active, I know when the sync is complete, and the terminal stays open for me to notice the outcome if I've been looking the other way at the moment the sync ends (see pic).
Is this method ok?
cheers!
SyncComplete.jpg
 Description   
 Filesize   4.67 KB
 Viewed   195 Time(s)

SyncComplete.jpg

Back to top
View user's profile Send private message 
puppyluvr


Joined: 06 Jan 2008
Posts: 3416
Location: Chickasha Oklahoma

PostPosted: Sun 10 Apr 2016, 17:16    Post subject:  

Very Happy Hello,
Thank you!

_________________
Close the Windows, and open your eyes, to a whole new world
I am the Admin of the
Puppy Linux Users Group on Facebook
Join us!

Puppy since 2.15CE...
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [12 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0571s ][ Queries: 12 (0.0054s) ][ GZIP on ]