Put an icon on the Desktop that runs a script
Introduction:
Say there's a script that you run fairly often and it's a pain to keep having to open up a Terminal and type it. This can be run by a launcher icon on the Desktop - well, under the right circumstances.
Those circumstances meaning, how you interact with it. If your script contains, for example, "ls -l", it will launch, list the directory and close - all before you get to see what's going on. This is only really useful for scripts that do something in background (e.g. writes something to a file), or are interactive (e.g. contain statements that ask for input).
Aim:
Create a Desktop icon that, when double-clicked, will run a shell script.
Requirements:
- Well, you need a Desktop and, for this particular example, root must have given you sudo permission to run /bin/mount - though there are many uses for this that need no sudo permissions at all.
- Do the 'User Actions' part of the 'Enable users to run normally excluded stuff using sudo' procedure.
Procedure:
This example creates an icon that mounts a floppy with a vfat file system.
- Create a shell script to mount a floppy:
- Open Terminal
- If ~/bin does not exist: $ mkdir bin
- $ cd bin
- $vi mount_floppy_vfat.sh
- Enter the line: sudo mount -t vfat /dev/fd0 /media/floppy (If you are root, you don't need the 'sudo' part.)
- Save and exit.
- $ chmod 744 mount_floppy_vfat.sh
- Create a launcher:
- Find a blank piece of desktop and right-click on it.
- -Create Launcher-
- Name: Mount Floppy (vfat)
- Generic name: Mount floppy
- Comment: 'Runs: sudo mount -t vfat /dev/fd0 /media/floppy'
- Command: [Browse]: Navigate to bin: -mount_floppy_vfat.sh-: [Open]
- Type: -Application-
- [No Icon]: This displays some icons. I use 'disks.png' for this: [OK]
- Run in terminal
- [OK]
When you hit [OK], you should see the new icon on the Desktop - called 'Mount Floppy (vfat)'.
Put a floppy in the drive and double-click the icon. The first time you do this, it will ask for a password. Use your user password. The disk should whirr a bit and then the 'floppy' icon appears on you Desktop. Note: it may appear over the top of an existing Desktop icon. I don't feel the need to find a solution to this right now.
Double-clicking the 'floppy' icon should open a browser to the floppy's file system.
To unmount the disk; right-click the 'floppy' icon and choose -Unmount Volume-. The disk should unmout, the browser closes, and the 'floppy' icon disappears.
1 Comments:
Testing comments
By Anonymous, at 8:49 am
Post a Comment
<< Home