How to bulk dismiss apple script dialogs? - python

I'm calling a apple script dialog from python as so:
import subprocess
applescript = """
display dialog "Some message goes here..." ¬
with title "This is a pop-up window" ¬
with icon caution ¬
buttons {"OK"}
"""
subprocess.call("osascript -e '{}'".format(applescript), shell=True)
However, based on certain conditions of my app, the notifications may go into the 100s i.e., too many dialogs may get queued up and dismissing each one manually by clicking on their respective "OK" buttons wouldn't be feasible. So what I'm looking for is a another apple script that I can use probably straight from the applescript editor that can clear these dialogs for me. A bonus would be to capture their text & timestamps into a text file, but just clearing them is something I need.
I'm new to Mac/applescipts and have not found a valid solution. I've tried the following:
tell application "System Events"
tell process "NotificationCenter"
set numwins to (count windows)
repeat with i from numwins to 1 by -1
click button "OK" of window i
end repeat
end tell
end tell
and
tell application "System Events"
click button 1 of windows of application process "TextEdit"
end tell
Can someone guide me in terms of how to achieve this? Thanks!
Alternately,
If there is a way to "separate" notifications for each iteration of:
b = """
display notification "All graphics have been converted 2." with title "My Graphic Processing Script" subtitle "Processing is complete." sound name "Frog"
"""
subprocess.call("osascript -e '{}'".format(a), shell=True)
then, that would work as well. Currently what's happening is each iteration of the notification is stacking on top of each other- ie., when multiple of them gets generated, I only see the latest one, or the number of such notifications. I instead would like to see all the notifications- perhaps have them stacked vertically- for eg: first notification displays in top right, and when second notification appears before the first disappears then, the first notification can get pushed downwards and the second one can be displayed on top of that. Similarly the third one can push both the first and second downward and then be on top of them and so forth.
Can this be achieved?
Basically, I need to see the content of all such notifications- either passively or actively requiring clicks. But in both cases, dismissing the notification should not impede my work. This is a monitoring application so based on certain conditions it would throw notifications my way- which the more close to real time, the better- so thats why I need to view all my notifications, as they appear, rather than write to some csv or txt file and me physically check that file periodically- which would be an unsustainable work flow.

I don't fully understand what you're trying to accomplish. If you don't like having dialogs, why are you putting dialogs in your script.
Anyhow, here are a couple ideas:
Add
giving up after 1
to your display dialog command, which will dismiss each box automatically after 1 second.
In place of the dialog box, how about putting instead a command to write a time stamp or whatever to a text file. Then you can check the text file to see it all worked.

Related

How can I close automatically or block modal(?) popup?

modal popup and marked blue left below
Is there any way to block modal(? - this is my understing for the box) popup automatically? I'm working on Mac, The bule color marked in left below is saying "do not open one day". I clicked check-box but it shows continuously. My searching result is such popup is called modal/layered popup - I have no idea for such technology. Please help how to block or click automatically by using Pythoin, javascript or Apple script. I'm using Keyboard maestro app so I can put such code before or after opening site which has modal(?) popup. I need to open 8-10 sites so need help.
tried to remove cookies but appear continuously. I think it's better click check-box automatically. Alternative if any is also good if can click "do not open one day" checkbox automatically.

Code to listen for changes in a pywinauto Listbox

I'm using pywinauto to interact with the window of an old game - specifically the dedicated server GUI. I've been able to connect to it with:
app = Application(backend="uia").connect(path=r"C:\Program Files (x86)\___.exe")
Using a loop, I'm able to read each line in a Listbox in a specific window using:
for i in dlg.ListBox.descendants():
print (i.window_text())
The Listbox behaves as like a console output area and I've also been able to write commands to the Edit (input) field which appear in the Listbox.
All of this is great considering I didn't think it would be easy at all!
However, the last part of what I'd like to do is proving more difficult...
I want to listen for changes in the list box so I can react to them and write different responses back into the Listbox. So for example, when a player joins the server, I want my code to know that a new line has appeared in the Listbox (so I can write a custom welcome message to the Edit field).
I have tried to look at listener scripts but I feel a bit out of my depth and can't seem to find a simple code example that could help me accomplish this. Does anyone have any ideas where I could look or what I could use?
Even better... would anyone be able to provide some sample code for me to re-work?

Daemonize, making program to work in background in python/wx.python

I created an complete logger-type program, that logs the certain data from the internet sources. It's GUI I coded in wx.python, now I want to daemonize it (if it is the right term). The program needs to run in background and user has to have option to call/open GUI when he pleases. How can I achieve this with wx.python?
I wouldn't really "daemonize" it per se. Instead, I would just put it in the system tray...at least, that's what I would do on Windows. I assume you can do something similar on the other OSes. Basically you want to bind the frame to wx.EVT_ICONIZE and in that method, you hide it. Then when the user double-clicks the taskbar icon, you want to show it and probably Raise it too.
There's some badly formatted code here: http://bytes.com/topic/python/answers/699757-wxpython-how-minimize-taskbar (I've used a variation of it myself, so I know it works).
And here's some information on Task bar icons: http://www.blog.pythonlibrary.org/2011/12/13/wxpython-101-creating-taskbar-icons/

How to send the text pasted in a textbox of a html webpage to the application written in python in the harddisk?

I have a application running in python, i want to send the input taken from the text box of the webpage and send it as input to the application and once again the output of the application which is in text format back to the result page on web.
thanks a lot for your time :) :)
Here's my suggestion: modify your program to include a button for doing the transformation. When you click it, it should take the contents of the clipboard, do whatever transformation you want, and put the result back on the clipboard.
Once you do that, to use it you select the text from the widget, use the keyboard to copy it to the clipboard, press the button on the GUI, then click back in the widget and use the keyboard to paste.
Alternately, your program can just poll the clipboard every couple of seconds, do the transformation and put the results back (make sure your automatic polling ignores any changes caused by itself). With that you can do a select-all, copy, wait a couple seconds, then paste.
This is pretty trivial to do in both Tkinter and wxPython, and I would guess it is equally trivial with most other GUI toolkits.
Have you tried PyQt4 which has this ability built-in? You can do what you're asking in about ten LOC.

Close an easygui Python script with the standard 'close' button

I've created a very simple app, which presents an easygui entrybox() and continues to loop this indefinitely as it receives user input.
I can quit the program using the Cancel button as this returns None, but I would also like to be able to use the standard 'close' button to quit the program. (ie. top right of a Windows window, top left of a Mac window) This button currently does nothing.
Taking a look at the easygui module I found this line:
root.protocol('WM_DELETE_WINDOW', denyWindowManagerClose )
This would seem to be the culprit. I'm no TKinter expert but I could probably work out how to alter this handler to act the way I want.
However, as I'd rather not mess about with the easygui module, Is there a way to override this behavior from my main script, and have the close button either close the program outright or return None?
It would require altering the easygui module, yes. I will get it modified!
** I have sent in a e-mail to the EasyGUI creator explaning this [12:12 PM, January 23/09]
** I just want to say that the possibility of this change happening - if at all, which I doubt - is very tiny. You see, EasyGUI is intended to be a simple, discrete way to create GUIs. I think that this addition wouldn't help any, especially since the interface is very sequential, so it would be confusing to new users. [12:19 PM, January 23/09]
** The EasyGUI creator said this in reply to my e-mail:
An easygui dialog should never exit
the application -- it should pass back
a value to the caller and let the
caller decide what to do.
But this is an interesting idea.
Rather than simply ignoring a click on
the "close" icon, easygui boxes could
return the same value that a click on
the "cancel" button would return.
I'll meditate on this.
-- Steve Ferg
I think that this is progress at least. [2:40 PM, January 23/09]
I don't know right now, but have you tried something like this?:
root.protocol('WM_DELETE_WINDOW', self.quit)
or
root.protocol('WM_DELETE_WINDOW', self.destroy)
I haven't tried, but google something like "Tkinter protocol WM_DELETE_WINDOW"
I found a solution, the answer is below the choice box, when he defines some functions (you can just type to find denyWindowManagerClose) and go to where he defines it. Just erase it and put this code in its place.
def denyWindowManagerClose():
#------------------------------------------------------------------
# Changed by ProgrammingBR
# Enables the user to close the window without entering a value
# Youtube URL: https://www.youtube.com/channel/UCTZh6kWz_iYACNE6Jcy2lhw
#------------------------------------------------------------------
global __enterboxText
__enterboxText = None
boxRoot.quit()
You can create a backup file, but this will work for all boxes, the suggestions given here aside from this will not work, I tried the them. if you want to see I have a video on it (it is in Portuguese, but you can follow it) just go to the youtube channel, I will upload it soon and post the link here :)

Categories

Resources