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 Tue 25 Nov 2014, 21:33
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 Posts_count  
Author Message
rcrsn51


Joined: 05 Sep 2006
Posts: 9260
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

Edited_times_total
Back to top
View user's profile Send_private_message 
abushcrafter


Joined: 30 Oct 2009
Posts: 1447
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_website 
abushcrafter


Joined: 30 Oct 2009
Posts: 1447
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_website 
rcrsn51


Joined: 05 Sep 2006
Posts: 9260
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: 1447
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_website 
rcrsn51


Joined: 05 Sep 2006
Posts: 9260
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: 1447
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_website 
steve_s


Joined: 26 May 2008
Posts: 1545
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_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 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0616s ][ Queries: 11 (0.0059s) ][ GZIP on ]