First of all, sorry for my english, not a native speaker.
Since I'm a bit fed up opening Termninal and ^C I want to create a shortcut for activating caffeinate -d on my Mac OS X 10.11
I've been trying a simple Automator Service but with my noob skills it doesn't work.
This is the settings:
I chose Service as type of document
Library->Utilities->Run Shell Script
Service receives: no input
in: any application
Shell: /bin/bash
Pass input: to stdin
CAFFEINATECHECK=`ps | grep caffeinate | cut -d ' ' -f7,8`
if [ $CAFFEINATECHECK == 'caffeinate -d' ]; then
killall caffeinate
else
caffeinate -d
fi
Problem is that such a short scrip keeps running with no response and I have to stop it after a minute
I hope someone could give me any tips necessary
I got the solution in a duplicate on Ask Different
In short, just replacing mine code with a more elegant command lines:
if [[ $(pgrep caffeinate) == "" ]]; then
caffeinate -d &
else
pkill caffeinate
fi
The only change I made inside user3439894's solution was to remove the '&' (usually useful at the end of a command line to run it in background) because apparently Automator doesn't work well with it (shame I can't remember where I read/heard that..!) .
After saving the Service I just had to
Open System Preferences Keyboard->Shortcuts->Services
Bind my shortcut with my saved workflow found under ▼General in the right pannel
This way a cog gear wheel ⚙ appears on the menubar when caffeinate shortcut is activated and spins till I deactive it .
Related
I want a script to check if it has been started from within a terminal window. If it was started without window, it shall re-run itself in a visible terminal window.
If found this script line:
tty -s; if [ $? -ne 0 ]; then konsole -e "$0"; exit; fi
It works fine. However since it uses konsole, it is specific to KDE. Is there a more portable solution that runs on Linux system without KDE as well?
No generic solution exists that will work over ALL window systems. however, you can look into implementing a list of common terminal programs. Good thing all take '-e'.
if [ ... ] ; then
for t in konsole gnome-terminal xterm ; do
if type "$t" >/dev/null 2>&1 ; then
$t -e "$#"
break
fi
done
Also note that 'tty -s' checks if your current stdin is connected to a terminal. You probably want to add a test for valid display ("$DISPLAY"). No point in launching a terminal window, if not running under some window manager.
You can improve code further by checking for environment variables that let you know if you are running under terminal: 'GNOME_TERMINAL_SCREEN', 'XTERM_SHELL', or checking of '$TERM' for 'xterm*'.
I'm currently using a terminal and vim on OSX as a development environment for Flutter. Things are going pretty well except that the app does not reload when I save any dart files. Is there a way to trigger that behavior?Currently I have to go to the terminal and hit "r" to see my changes.
Sorry for the plug, but I wrote a very simple plugin to handle this.
It makes use of Flutter's --pid-file command line flag to send it a SIGUSR1 signal.
You can achieve the same result as my two-line plugin by adding this to an autocmd
silent execute '!kill -SIGUSR1 "$(cat /tmp/flutter.pid)"'
And launching Flutter with the --pid-file flag.
I made a vim plugin hankchiutw/flutter-reload.vim based on killing with SIGUSR1.
You don't have to use --pid-file flag with this plugin. (Thanks to the pgrep :))
Simply execute flutter run, modify your *.dart file and see the reloading.
I did it with the excellent little tool called entr. On OS/X you can install it from brew: brew install entr. The home page of the tool is at http://eradman.com/entrproject/
Then you start flutter run with the pidfile as #nobody_nowhere suggests.
How do you run entr depends on the level of service. In the simplest case you just do find lib/ -name '*.dart' | entr -p kill -USR1 $(cat /tmp/flutter.pid)
But such invocation will not detect new files in the source tree (because find builds a list of files to watch only once, at the start). You can get away with slightly more complex one-liner:
while true
do
find lib/ -name '*.dart' | \
entr -d -p kill -USR1 $(cat /tmp/flutter.pid)
done
The -d option makes entr exit when it does detect a new file in one of the directories and the loop runs again.
I personally use even more complex approach. I use Redux and change to middleware or other state files does not work with hot reload, it doesn't pick up these changes. So you need to resort to hot restart.
I have a script hotrestarter.sh:
#!/bin/bash
set -euo pipefail
PIDFILE="/tmp/flutter.pid"
if [[ "${1-}" != "" && -e $PIDFILE ]]; then
if [[ "$1" =~ \/state\/ ]]; then
kill -USR2 $(cat $PIDFILE)
else
kill -USR1 $(cat $PIDFILE)
fi
fi
It checks if the modified file lives in /state subdirectory and if true does hot restart or else hot reload. I call the script like that:
while true
do
find lib/ -name '*.dart' | entr -d -p ./hotreloader.sh /_
done
The /_ parameter makes entr to pass the name of the file to the program being invoked.
You don't say what platform, but all platforms have a "watcher" app that can run a command when any file in a tree changes. You'll need to run one of those.
vscode has this feature. If you don't mind moving to vscode you can get it out of the box. You could also reach out to the author and see if they have any suggestions on how you could do it in vim or check the source directly. Most likely vim will have a mechanism to do so.
I have a computer running Ubuntu with retropie (emulationstation) which i can create .sh files to run linux based steam games through as they can be directly installed onto the computer. I have installed wine in order to play the windows based games and while I can run the files by going into windows steam and clicking play, I am looking for a way to create a .sh file that will allow me to play them through retropie. I can post some of the stuff ive tried i just am struggling with the formatting.
Let me know if i need to post anything else or fix something!
EDIT: Heres some of the code ive tried, the first i thinks should run the executable through wine but i cant get anything to output, the second is some code i found online which watches for the game to close as well so it can exit clean.
#!/bin/bash
wine ~/PlayOnLinux\'s\ virtual\ drives/Steam/drive_c/Program\
Files/Steam/steamapps/common/MortalKombat_KompleteEdition/DiscContentPC/MKKE.exe
#! /bin/bash
appid=$1
procname=$2
PREFIX=/home/rig-cade/PlayOnLinux\'s\ virtual\ drives
STEAM="/home/rig-cade/.wine-steam/drive_c/Program Files/Steam/Steam.exe"
export WINEDEBUG=-all
export WINEPREFIX=$PREFIX
if [[ ((`pgrep -f steam.exe -c` == 0)) && ((`pgrep -f Steam.exe -c` == 0)) ]]; then
optirun wine "$STEAM" -silent &
sleep 20
fi
echo "Running game"
wine "$STEAM" steam://rungameid/$appid &
sleep 15
echo "Starting checks"
status=`pgrep -f $procname -c`
if (( "$status" > 1 )); then
while (( "$status" > 1 )); do
sleep 5
status=`pgrep -f $procname -c`
done
wine "$STEAM" -shutdown &
fi
echo "Exiting"
I'm not 100% sure and I will test once I get done with work in a couple hours, but AFAIK the Steam URL protocol cannot be used with the command-line and so when you try this Steam is likely throwing a parsing error. If you add -console after -silent it should enable the Console tab and allow you to see an error message if you open the client.
Instead try one of
Only using the browser protocol without the "$STEAM" part so it's not trying to pass it as an argument to the client.
Using the Steam Command-line parameter -applaunch {appid},
where {appid} is replaced with the appid of the game to be run as you were already trying to do.
I'm trying to wrap my head around this but I can't. I wanted to make a cron that checks a process is up. If so, write to a file that it is up. Else, use this script to start it again, and log the fact that it was dead.
Here's what I came up with:
pgrep -f app -u silv && echo "$(date) app is online" >> /home/silv/app_status || echo "$(date) app is dead" >> /home/silv/app_status && /home/silv/apps/app/bin/start-app.sh
If the app is up, it writes correctly in the log file, that it's online.
If the app is not up, it still writes that it is online BUT also start's the app.
What am I missing?
Turns out I didn't understand how '&&' and '||' actually work in Bash.
This answer explains it, the gist being that both AND and OR operators have the same precedence in BASH
I am creating an application installer for Mac. The installer involves getting a code from the user on install. I used an Installer Plugin for the Code Input screen.
I have read (from this link) and verified that plugins do not work in the command line and Apple Remote Desktop. I can check if the installer is running from the command line using a variable ("$COMMAND_LINE_INSTALL").
My questions is, how can I programmatically check if it is running via Apple Remote Desktop?
If pstree is available, you can get a quick ancestry of the current process and see if Apple Remote Desktop is in it, something like pstree -p $$ in bash. Unfortunately, I installed pstree using brew, so this is most likely not going to be available for you, unless you distribute a binary yourself.
The other approach is to walk up the parent yourself. Here is a sample that I tested to be working to check if I am running inside iTerm (I used iTerm as a sample because I don't know what the pstree output would look like when running inside Apple Remote Desktop).
pid=$$
running_in_iterm=0
while [ $pid -ne 1 ]; do
command=$(ps -o command= -p $pid)
case "$command" in
*iTerm*)
running_in_iterm=1
break;;
esac
pid=$(ps -o ppid= -p $pid)
done
if [ $running_in_iterm -eq 1 ]; then
echo "Running in iTerm"
else
echo "Not running in iTerm"
fi
You can try running this script from both the built-in Terminal app as well as iTerm and see the difference.