Sponsored Content
Top Forums Shell Programming and Scripting Problem with script invoked from a keyboard shortcut Post 302670465 by gencon on Thursday 12th of July 2012 06:03:51 AM
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..
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
exit(1) 							   User Commands							   exit(1)

NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps SYNOPSIS
sh exit [n] return [n] csh exit [ ( expr )] goto label ksh *exit [n] *return [n] DESCRIPTION
sh exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of the last command executed (an EOF will also cause the shell to exit.) return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe- cuted. csh exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the expression expr. The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to jump to a label that occurs between a while or for built-in command and its corresponding end. ksh exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit except for a shell which has the ignoreeof option (See set below) turned on. return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return is invoked while not in a function or a '.' script, then it is the same as an exit. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 exit(1)
All times are GMT -4. The time now is 07:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy