awesome wm: pop yes/no dialog when killing a window - zenity

In awesome wm when I press mod-q I kill the current window. I would like to pop a yes/no dialog to confirm the action:
if zenity --question --title='Quit?' --text='Quit?'; then kill_the_window; fi
But, the killing function is run from the Lua code in rc.lua, not from the shell.
awful.key({ modkey, }, "q", function (c) c:kill() end)
How to make the awesome wait for the zenity output before killing the window,

Awesome is written in lua, so all you need to know is how to capture the exit status of a program run by lua. See this question.

Related

Run Power Automate flow from Windows Desktop via shortcut key or command line / shell

I would like to run a Power Automate flow by pressing a keyboard shortcut or alternatively calling it up from CMD or Powershell script.
The flow would simply start execution once the keyboard shortcut is pressed or a Powershell script is run.
As it is now; I need to start Power Automate and then click on play in order to start a specific flow. I am trying to avoid all that.
The ultimate goal is to, once the system is up (Windows 10) and I'm logged it, I press the shortcut key and go do something else and by the time I get back the flow is done. The flow itself works flawlessly. Please note that I am not looking for a solution which would involve smartphones and flow buttons on said phones, purely a Windows , PC, only solution or a way to a solution.
Here is a picture to clarify what Lukas was describing as a workaround.
Create a loop and make sure that the index variable for the loop is 0 so that it will never stop looping. Then make sure to put a 'wait for shortcut key' inside of the loop with you desired shortcut. Below that action and still inside of the loop, put all of your actions.
Run the script and the script will enter the loop at the 'wait for shortcut action. When the shortcut is pressed it will run all of the actions and then loop back to the 'wait for shortcut action again. As long as the script is running in the background the shortcut can trigger it.
Surprisingly, I do not think there is a way to do this. The best solution would probably be to use AutoIT to create a small automation to start your PAD flow.
As long as you're somewhat familiar with programming and even if you're not familiar with AutoIT, it shouldn't take you but a couple hours to write a script that is activatable via hotkey that opens PAD and starts the flow you want.
The AutoIT help file that you get when you install should be all the guidance you need.
(Depending on what your flow actually does, you might be better off just writing your whole automation in AutoIT)
You actually don't need to put everything in a loop, the loop is just from the end of the script to the top label. You just need a label at the top (if you want to be able to press the shortcut more than once), a wait for shortcut key event, and at the end a "go to the label" you created (in the image below it's 'start').
Then you can save the flow and start it. Nothing will happen until you press your shortcut key. Then the flow will execute, and return to the top, waiting for you to press your shortcut again.
You can even have errors go to the start label, instead of ending the script, so that the flow "stays alive".
Just put label on top of your code and then "Wait for shortcut key" and at the end use "go to" function, that will loop the code. This works for me

How to save the life of my process?

I have the following problem: I want to run a really cumbersome calculation on a server via Putty in Matlab. Now I do not want to keep my notebook the whole time connected to this server, which is why I am searching for a solution to this problem. I know that screen in general works but I am not sure whether this could help me here too. The problem is the following: Each time I start this Matlab program I have no longer control over the terminal, since the Matlab program is still running. Therefore I am always forced to abort the process, which is what I do not want to happen. Is there anything that could help me.
What I need this:
1.)Start Matlab Application on server
2.)Disconnect from Server
3.)Connect to Server
4.)Have access to Matlab again
I would highly appreciate it, if somebody could give me a reference to some commands that might be helpful in this situation.
As #Peter said, screen is one good solution. A brief tutorial:
Connect to server
screen -S SectionName
matlab -nosplash -nodesktop or -nodisplay or -nojvm depending if you have allowed X11 forwarding on putty (you can check this by simply open a figure and check if you can see it with -nodesktop option)
Ctrl+a d to detach
Log out
Reconnect to server
If you are using X11 forwarding, you may need to update your display on the screen, so: echo $DISPLAY, copy its result
screen -rd SectionName
If you are using X11 forward, update display on screen export DISPLAY="value echoed outside screen" (I think the opposite also works, you set the log display into the screen display)
Finish Screen
Exit matlab and type exit
List open screens
screen -ls
Terminate unresponsive screen
Ctrl+a Ctrl+k and answer y
Navigate through screen screen:
Ctrl+esc and then use arrows or: ctrl+u to go half screen up and ctrl+d to half screen down
Exit broken connection screen
~ .
Note: You can have more than one screen section running, or you can open multiple screen windows by using Ctrl+a Ctrl+c
Note2: screen command may be very addicting, use it with cautious. Don't forget to read its man page.

Eclipse After Running the file

Whenever i run Hello World Using C programming and Eclipse it shows Console as blank White, and the only method for me to view an output on a console is to click the red button "Terminate button" and it will show the output on console.
Is there a way to fix this, whenever we click run it will run the program and show the output on the console without having to click the terminate button?
Thank you very much.
I don't know what do you mean by "it shows blank white" as if it is closed quickly or hangs ?
but try adding
fflush(stdout);
while ( getch() != '\n' )
after your printf statement
As you can press the red "Terminate" button, your program can be started but hangs and never terminates by itself. We will need to see the source code of your program to tell you why.
Also, don't forget to add \n at the end of your printf() string or force a flush of the output with fflush(stdout);

Why doesn't this applescript seem to work as expected?

I'm writing a service using automator. It receives no input in any application.
All it does is run this simple script:
on run {input, parameters}
--FIRST BLOCK
tell application "System Events"
set app_name to name of the first process whose frontmost is true
end tell
--SECOND BLOCK
if (do shell script "defaults read com.apple.finder AppleShowAllFiles") is equal to "0" then
do shell script "defaults write com.apple.finder AppleShowAllFiles 1"
else
do shell script "defaults write com.apple.finder AppleShowAllFiles 0"
end if
--THIRD BLOCK
do shell script "killall Finder"
delay 0.5
--FOURTH BLOCK
if (app_name is equal to "Finder") then
tell application "Finder"
activate
end tell
end if
end run
I'll walk you trough it step by step:
first block: get the name of the current frontmost app and store it in a variable app_name.
second block: toggle the hidden files variable on or of, depending on its value.
third block: run killall Finder to relaunch Finder, taking the toggle from the second block into effect. Pause 0.5 sec, somehow this is necessary (don't know why, but without this the next instruction will be ignored).
fourth block: Check what the variable app_name was. If it equals Finder this means finder was active when the script was initiated, thus activate Finder once more (killall Finder leaves it in the background).
Problem: Everything works as expected but for one thing: when using this service in the Finder, Finder doesn't get activated again.
One might argue that there must be something wrong with the code in the fourth block, yet I've experimented a bit to show everything works as expected:
When I replace equal by not equal and run the script from any app that is not the Finder, Finder DOES get activated as should be.
So it seems that there only is a problem when the script is fired when Finder is in front.
(This is what the service should do: from within any app, toggle the visibility of the hidden files in Finder. When Finder was in front, it should be in front after execution of the cript, when another app was in front, this app should still be in front.)
I'm on Lion.
I have come across this before too. Basically you're saying that when this gets run when the Finder is frontmost that the Finder is not really frontmost. And that is true because you said this is an automator service. I believe automator stuff is run by an application named "Automator Runner". So actually as soon as the service is run Automator Runner becomes frontmost. Note that it is a faceless application so you can't see that it's frontmost but it is. So when you check if the Finder is frontmost it never is. Does that make sense? I see the same thing when running applescripts because they're run using Applescript Runner.
So how do you fix this? Here's a thought. Make this your FIRST BLOCK and see if it helps...
tell application "System Events"
set app_name to name of the first process whose frontmost is true
if app_name is "Automator Runner" then
set visible of process "Automator Runner" to false
set app_name to name of first process whose frontmost is true
end if
end tell
NOTE: I'm not certain that Automator Runner will be the frontmost process. It may be something else like the name of your automator action. But you can be certain something else is frontmost because of the automator action being run... so if my code doesn't work then you just have to figure out the name of the process that's running when your automator action is running and put that into the code. You can always put a "display dialog" in your code to show you the name of the frontmost process.
One other tip. In general I do not like to use the KILLALL command if I can use a QUIT command instead. Quit is designed for the Mac and makes sure things are stopped gracefully. As luck would have it the Finder has a quit command. Try this for your 3rd and 4th blocks. You'll see that if the Finder was frontmost then we activate it which makes it frontmost again but if it wasn't then we launch it so it is at least running again but doesn't come to the front.
-- quit the Finder
tell application "Finder" to quit
-- delay until the Finder quits
repeat
try
tell application "System Events" to get first process whose name is "Finder"
delay 0.1
on error
exit repeat
end try
end repeat
-- restart the Finder
if (app_name is equal to "Finder") then
tell application "Finder" to activate
else
tell application "Finder" to launch
end if
EDIT: It seems your step #2 is incorrect. You need to use "ON" or "OFF" instead of 0 or 1. Try this...
if (do shell script "defaults read com.apple.finder AppleShowAllFiles") is equal to "ON" then
do shell script "defaults write com.apple.finder AppleShowAllFiles OFF"
else
do shell script "defaults write com.apple.finder AppleShowAllFiles ON"
end if
A slight modification of #regulus6633’s script works on my machine:
-- restart the Finder
tell application "Finder" to launch # always launch
if (app_name is equal to "Finder") then
tell application "Finder" to activate # activate separately
end if
I must admit I am not entirely sure of the why and how – the AppleScript documentation for the launch and activate commands does not seem to be adequate in Finder’s case…

How can I script GNU Screen to start with a program running inside of it so that it does not exit the session on program completion?

How can I script GNU Screen to start with a program running inside of it so that it does not exit the session when the program completes?
I want to run an interactive program as a daemon, if I manually start screen and then launch this program inside of it everything works just as I want. If the program exits or crashes the screen session remains and I can go look at it to see what just happened. However, if I start the program with a simple screen launch then it does run inside of screen but when the program exits the screen session ends and any output from the program is lost.
So screen –dmS serverName serverApplication does not work for my scenario. I did think about making a script which launches the program I want to run & then sleeps forever, I could then launch the script at the same time as screen and should get the effect I am after but it seems rather an untidy way to do things and I am sure there must be something more elegant.
I have read quite a few screen tutorials and trawled through the man page but nothing leaps out at me as the right way to do this. I did try –X but that is for screen commands, not for running commands inside the screen session... Any suggestions will be very much appreciated; I am even happy to use something other than GNU Screen if there is a better tool for use in scripting but please give me an example where possible.
(Side note: The two things I will be running with this are a minecraft_server and a mythtv_backend. My plan was to launch these from a chron job at boot via some ruby/bash script)
First, you'll want to start a daemon screen session just running your default shell:
$ screen -dmS "serverName"
Then, send your command to that shell using screen's stuff in combination with -X:
$ screen -S "serverName" -p 0 -X stuff "serverApplication$(printf \\r)"
The -p is important for telling screen into which window within that session to stuff the command. In this case, it's the only available window, 0, but if you don't specify that, for some odd reason your command will go nowhere. The $(printf \\r) sends a 'Return' keystroke. A regular \n might work in its place, but I've read that's shell-dependent. The newline character does not work in bash; I can vouch for that.
Here's another cool trick. If you want to then make another screen window within that session, you can:
$ screen -S "serverName" -X screen
Now you can send commands to that one using the same syntax as above, but with -p 1. Lots of fun.