Skip to content

u/eripx

In this archive from Mar 2019 to Feb 2021

0
posts
10
comments
0
media
40
score

Including a kill statement might look something like:

#!/bin/bash

PROCESS=spotify
number=$(ps aux | grep -v grep | grep -ci $PROCESS)

if [ $number -gt 0 ]
then
	PID=$(ps -ax | grep spotify | grep -v grep | awk '{print $1 }')
	kill -9 $PID;
else
	open -a Spotify;
fi
1 points

On mac, the open binary can be used to launch an application. I'm not sure if this exists in other environments. The below will check if Spotify is running and if it is, it echos "Running", but if it isn't it launches Spotify. The next step is to include the kill command if Spotify is already running instead of the echo.

#!/bin/bash

PROCESS=spotify
number=$(ps aux | grep -v grep | grep -ci $PROCESS)

if [ $number -gt 0 ]
then
	echo Running;
else
	open -a Spotify;
fi
0 points

I found your idea interesting and spent a little bit working on part of it. The below snippet successfully checks if Spotify is running and reports "Running" or "not running" depending. This could be modified to launch or kill Spotify instead of echoing the status.

#!/bin/bash

PROCESS=spotify
number=$(ps aux | grep -v grep | grep -ci $PROCESS)

if [ $number -gt 0 ]
then
	echo Running;
else
	echo not running;
fi
2 points

End of this list.

Back to top

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.