Dav*_*ill 6 xfce command-line scripts
我希望能够有一个键盘快捷方式来启动或将程序带到前面。(sqldeveloper,如果重要的话)
我知道如何运行它,这留下了:
1) 我如何知道一个程序是否已经在运行?
2)如何将程序带到其他打开的窗口的顶部?
~~编辑~~
感谢您到目前为止的答复。当我运行这些命令中的任何一个来获取正在运行的进程列表时,我得到以下信息:
doneill 3492 1 0 Nov16 ? 00:00:00 /bin/sh /usr/local/bin/sqldeveloper
doneill 3493 3492 0 Nov16 ? 00:00:00 /bin/bash /opt/sqldeveloper/sqldeveloper.sh
doneill 3495 3493 0 Nov16 ? 00:00:00 bash sqldeveloper
doneill 3552 3495 1 Nov16 ? 00:25:07 /usr/lib/jvm/java-6-sun-1.6.0.22/bin/java -Xmx640M -Xms128M -Xverify:none -Doracle.ide.util.AddinPolicyUtils.OVERRIDE_FLAG=true -Dsun.java2d.ddoffscreen=false -Dwindows.shell.font.languages= -XX:MaxPermSize=128M -Dide.AssertTracingDisabled=true -Doracle.ide.util.AddinPolicyUtils.OVERRIDE_FLAG=true -Djava.util.logging.config.file=logging.conf -Dsqldev.debug=false -Dide.conf="/opt/sqldeveloper/sqldeveloper/bin/sqldeveloper.conf" -Dide.startingcwd="/opt/sqldeveloper/sqldeveloper/bin" -classpath ../../ide/lib/ide-boot.jar oracle.ide.boot.Launcher
Run Code Online (Sandbox Code Playgroud)
我确实通过 .sh 脚本启动它。它是一个基于java的程序。其中哪些是我感兴趣的?我尝试使用xdotool
来提出它,但我还没有成功,尽管今晚我没有时间深入研究手册页。
如果我运行xdotool search Orac
('Oracle SQL Developer' 是窗口标题的开始),它会返回一堆数字。其中之一是否代表了我感兴趣的内容?
一点点 bash 和xdotool应该可以解决问题。在帖子末尾安装 xdotool 的注意事项。
ActivateOrLaunch.sh
#!/usr/bin/env bash
# usage:
# ActivateOrLaunch.sh firefox-bin
#
# Will launch firefox-bin or activate the first window in the windows stack
# --- Remember to chmod a+x ActivateOrLaunch.sh in order to execute.
# pgrep looks through the currently running processes and lists the process
# IDs which matches the selection criteria to stdout
# for more information on pgrep http://linux.die.net/man/1/pgrep
# if process is found by pgrep then pipe through head to get firt instance in
# case of multiple processes running. If process not found $pid will be empty
pid=$(pgrep ${1} | head -n 1)
# Using "-z" check if $pid is empty, if so execute the process
if [ -z "$pid" ]; then
echo "$1 not running... executing..."
$1 &
else
# process was found, find the first visible window and activate it
echo "Found process $1 with PID $pid"
# using xdotool [http://www.semicomplete.com/projects/xdotool/] get the first
# visible windows using $pid. Redirect stderr to /dev/null and only select
# the first visible windows using head
wid=$(xdotool search --onlyvisible --pid $pid 2>/dev/null | head -n 1)
# if $wid is empty the process does not have any visible windows... do nothing
if [ -z "$wid" ]; then
echo "Didn't find any visible windows for process $1 with PID: $pid"
else
# send the window id ($wid) from the window stack to xdotool
echo "Activating first windows in stack"
xdotool windowactivate $wid
fi
fi
# ******** NOTES **********
# In order for this script to work correctly you need to pass the complete process
# name for it to find any visible windows. The process needs needs to be in the path
# for it to execute if not running.
#
# For example
#
# If you try it with firefox-bin on Ubuntu 10.10 it will find the running process and
# activate the window, but it will not be able to launch the process since the executable
# in the path is called firefox which is a link to firefox.sh
# (/usr/bin/firefox -> ../lib/firefox-3.6.12/firefox.sh) which in turn executes firefox-bin
# (not in path).
#
# Next, if you use firefox it will find a process but won't be able to find any windows
# since it's a wrapper function calling firefox-bin and doesn't have any windows.
Run Code Online (Sandbox Code Playgroud)
你可以在github上找到代码
我在 Ubuntu 10.10 (Gnome) 上测试了代码并且它工作正常。它需要一些润色,因为我只是输入它并且不担心让它变得漂亮(想确保得到评论)
要安装 xdotool,您可以apt-get install xdotool(从我这里获取版本 2.20100701.2691),如果您想要最新和最好的从这里获取它(截至 20101116,它是版本 2.20101012.3049-4)
归档时间: |
|
查看次数: |
5552 次 |
最近记录: |