Visit Our UNIX and Linux User Community


Problem with script invoked from a keyboard shortcut


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with script invoked from a keyboard shortcut
# 1  
Old 07-12-2012
Problem with script invoked from a keyboard shortcut

-EDIT-

I have solved my problem below by using a different program. Instead of xsel I am using xclip which basically does the same thing and works fine from a script invoked by a global hotkey.

-END EDIT-



Hi,

I've written a simple script to copy my email address into both the clipboard and the primary selection using a useful utility called xsel. This is so that I can assign a global shortcut key to the script to quickly paste my email address when needed.

Code:
#!/bin/bash

# Use xsel to copy email address to the clipboard and to the primary selection.

xsel < /home/user/scripts/email-address-in-this-file

xsel --clipboard < /home/user/scripts/email-address-in-this-file

# Play completion alert sound, test only to see if the script actually ran.
play -q "/home/user/Music/MiscSoundEffects/Beep_Done.wav"

When run from a terminal prompt, it works perfectly and I can paste the email address with <CTRL>V and by middle-clicking. However it does not work properly from the keyboard shortcut key - the script runs because the audio test sound plays, but my email address does not end up in the clipboard or in the primary selection.

If I use <Alt>F2 to bring up the Gnome 'Run Application' dialog box and enter the script's name the same thing happens (the audio test sound plays, but my email address does not end up in the clipboard or in the primary selection).

My guess as to what is happening is that there is a problem due to running the script in a shell instance which dies almost immediately.

I tried 3 ways around this, none fixed the problem:

1) I used the xsel option --keep in the xsel commands.

2) I got the xsel process Id using "$!" and then used "disown" on the process Id to disassociate the program from the shell instance it was running in. But I got "disown: : no such job" when run from the terminal command line - the job had finished before I could disown it.

3) I added "sleep 30" to the bottom of the script thinking that if I could get the shell instance to stay alive the email address might stay in the clipboard and in the primary selection.

None of these worked.

Any help sorting this out would be greatly appreciated. Many thanks.

PS. I will happily use another method of getting my email address into the clipboard or primary selection, I've used xsel because that was the only way I knew to do it.

Last edited by gencon; 07-13-2012 at 11:28 AM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #97
Difficulty: Easy
Unix is a multi-user operating system where the same resources can be shared by different users even if they do not have the proper permissions to do so.
True or False?

9 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Method to run a shell script using shortcut key in keyboard with out logging to putty

Dear All, I want to run a shell script with out logging to putty but configuring it to a keyboard short cut it windows PC. Can this be done? I want this to rename a log in a specified folder in a system Thanks (8 Replies)
Discussion started by: Chi_SL
8 Replies

2. UNIX for Dummies Questions & Answers

Problem getting vertical bar with British keyboard layout on US (physical) keyboard

Hi, I've got a bit of a ridiculous problem and wasn't sure where to post it. I need to use the vertical bar for piping in Bash but, as per the title, am using a UK layout on a US (physical) keyboard which doesn't have a key for it in the place I'd expect. I've tried using xbindkeys and Unicode... (7 Replies)
Discussion started by: crunchgargoyle
7 Replies

3. Shell Programming and Scripting

How to ensure a script can only be invoked from another?

Hi All, I have two scripts - ScriptA and ScriptB ScriptA has logic to invoke ScriptB : - with some parameter - or without any parameter ScriptB can also be invoked by the user from the command line. Is there anyway to ensure that when I execute ScriptB from the command line, it does... (3 Replies)
Discussion started by: chaitanya.gvc
3 Replies

4. OS X (Apple)

Copy entire line in bash (terminal) - keyboard shortcut

how can I do that? I can paste a line with ctrl+p; but I dont know how to copy it? ctrl+y - just deletes etc. (2 Replies)
Discussion started by: c_lady
2 Replies

5. Shell Programming and Scripting

CRON: Script not getting invoked

Hi, I have the following script - fixpart="/files/myScript # Transfer Script" echo "Specify the transfer frequency in minutes - " echo "every 1, 2, 3, or 5 minutes (default every 1 minute) " echo $nn "Frequency ? :" $cc read ans case $ans in 2) echo... (9 Replies)
Discussion started by: angshuman_ag
9 Replies

6. UNIX for Advanced & Expert Users

why the script name not displayed and not sh invoked?

Say there is a shell script named test.sh. I intentionally omit the #! line in test.sh for testing perpose. I did the following : $ echo $0 -ksh ---> current shell $ echo $$ 12919 ---> PID of the current shell... (4 Replies)
Discussion started by: hongwei
4 Replies

7. UNIX for Advanced & Expert Users

Passing the values to the secondary script when it invoked by primary script

Hi, When I invoke a script s1.sh it will call an another script s2.sh by itself. This script s2.sh will call some java files, so while running the script it asks for a file name to be processed. Which we can see in the screen. The file name to be processed is present in script s1.sh Now I... (2 Replies)
Discussion started by: venu_eie
2 Replies

8. Shell Programming and Scripting

Passing the values to the secondary script when it invoked by primary script

Hi, When I invoke a script s1.sh it will call an another script s2.sh by itself. This script s2.sh will call some java files, so while running the script it asks for a file name to be processed. Which we can see in the screen. The file name to be processed is present in script s1.sh Now... (1 Reply)
Discussion started by: venu_eie
1 Replies

9. Shell Programming and Scripting

determine if the script has been invoked manually or not?

Hi, Is there a way to determine if the script has been invoked manually or not( might be invoked by a schedular or crontab)? Thanks, (8 Replies)
Discussion started by: hitmansilentass
8 Replies

Featured Tech Videos