1

How is it possible to set the black dot in the close button of a window using applescript? From http://docs.realsoftware.com/index.php/Window.ContentsChanged_property, I would guess something like:

tell app "CurrentApp" to set ContentsChanged to true of window 1

But it doens't work: execution error: CurrentApp got an error: Can’t make ContentsChanged of window 1 into type specifier. (-1700)

Also, how can I get what the current application is with applescript? This question is related to Signifying unsaved changes by prepending * in window title - how to add a black dot in the window close button on Mac OS X?

Community
  • 1
  • 1
armando.sano
  • 345
  • 1
  • 3
  • 9

1 Answers1

0

To answer the second part of your question s first: you can get the current application with "the frontmost application", for example

tell application "Finder"
    set frontApp to the path to the frontmost application
end tell

The short answer to the first part of your question is: it is currently impossible to do what you want. Long answer follows below.

From your comments, I understand you are using Python with TCL/TK to build the GUI.

Not every application is able to set the "contentsChanged" indicator (apparently, this is what it is called in RealBasic but not in Apple's API). Check the AppleScript dictionary of the application. Relying on what I read elsewhere, TextEdit used to be able to set the "modified" property of its documents but when I try this in Mac OS X 10.6.8 it no longer works.

If you're using a native Cocoa application, you might be able to set this indicator by adding and removing a space to the document with some GUI scripting, e.g. type a space and use the Undo menu item to remove it. Unfortunately, when I try this in TextEdit, the Undo command also removed the indicator.

I checked Apple's API documentation and there appears to be a method SetDocumentEdited in the NSWindow class. Unfortunately, Apple doesn't describe properly what it does, but it appears to set the dark spot in the red close button if the DocumentEdited property is set to true. You can read about it here. If you're using TCL/TK, it would have to be able to call the SetDocumentEdited method somehow.

You can't tell the operating system to change the DocumentEdited property of a window (which would be the equivalent of the "modified" property you found in an AppleScript dictionary). The (Python-TCL/TK) application you're talking to needs to have this implemented. If TCL/TK doesn't have a command for this, then it is probably impossible, no matter if you use AppleScript or Python or something else. I'd suggest you ask on a TCL/TK forum if someone can write and compile a kind of plug-in to implement this feature.

Community
  • 1
  • 1
Mark
  • 2,380
  • 11
  • 29
  • 49
  • Thanks for the reply. How can you check the 'dictionary' of the application? It seems OS Lion has introduced a system-level auto-save function that makes applications that rely on it to not show the black dot anymore. – armando.sano Apr 08 '13 at 16:03
  • Mh. When you run a Python script with Tkinter (std GUI toolkit), the application window is not frontmost. The trick is to [call an apple script to do it](http://stackoverflow.com/questions/1892339/make-tkinter-jump-to-the-front): `os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')`. But if you 'freeze' your python script (kind of compile it), then the application name is no longer "Python" but the name of your binary, which may vary. I tried using your suggestion and then set frontmost replacing "Python" with frontApp but it didn't work. – armando.sano Apr 08 '13 at 16:17
  • In fact, may be it actually works, but it sets to frontmost not the python standalone binary (which creates a window), but the Terminal window (which is already frontmost) from which I execute the binary... (not a big issue though - I know the name of the binary - only it changes depending on whether it is installed globally (release) or not (development), which means I need to remember to modify the binary name within the python script. – armando.sano Apr 08 '13 at 16:22
  • Adding and removing a space doesn't work for me: this is exactly the behaviour I am trying to program :) My issue here is in fact inherited from [writing an editing window with tkinter and signify unsaved changes](http://stackoverflow.com/questions/15852462/signifying-unsaved-changes-by-prepending-in-window-title-how-to-add-a-black) – armando.sano Apr 08 '13 at 16:29
  • @DigiMonk: Thanks for the tip. Tried to open /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app from AppleScript Editor, but it said "The document Python.app could not opened"...? – armando.sano Apr 08 '13 at 16:36
  • 1
    ok, silly me. Using `Open dicionary...` instead of normal `Open` works. There I can see that the `Standard Suite`'s `document` heading has the property `modified`, which is exactly what I want to control – armando.sano Apr 20 '13 at 15:19
  • sorry, nope, the initial problem still remains. – armando.sano Apr 22 '13 at 01:55
  • Which programme are you trying to change the modified of? – Mark Apr 22 '13 at 10:04
  • It's a Python program. So, when run as a Python script, (#!/usr/bin/python) the application is "Python" (which interprets the script - the script itselfs creates new windows etc.). See above for full path of the program. The 'modified' property there seems a property of a document, not of a window, but again, I am unable to access this property properly, even when trying to set it on other applications (e.g. Terminal, Mail etc.). I would really appreciate any idea. Thanks. – armando.sano Apr 22 '13 at 13:01
  • Sorry. You can't tell the operating system to change the contentsChanged property of a window (which would be the equivalent of the modified property you found). The (Python) application you're talking to needs to have this implemented. If Python doesn't have syntax for this, then it is probably impossible, no matter if you use AppleScript or Python. I'd suggest you ask on the Python forum if someone can write and compile a kind of plug-in for Python to implement this feature. – Mark Apr 22 '13 at 15:17
  • 1
    Thanks for your answers. I first asked the question on the Python forum, see second link in my question. Ok so it would require Tcl/Tk (interfaced in Python in tkinter) to implement this mac-feature, but they don't from what I see [here](https://www.tcl.tk/man/tcl8.6/TkCmd/tk_mac.htm). Still, I am puzzled why you can access some GUI features of apple's window manager (or Cocoa etc) with applescript but not this one... Especially now that it seems there is more of a system-wide control of it with OS Lion. Thanks anyway. Please post your last comment as answer and I'll accept it – armando.sano Apr 23 '13 at 15:43