8
\$\begingroup\$

Inspired by The Most Useless Machine Ever.

Write the shortest program that does the following:

  • create a graphical window, then immediately close the window and exit the program.
  • do this in some visually apparent manner. Like the "arm" that pushes the switch in the machine, the program must use some visual method in the GUI to close itself.
  • this visual method must be what causes the program to close; you cannot just show it as something on the side (though there may be other things off to the side)

Note:

  • The program does not have to be visible long enough for the visible activity to be seen by a human as long as the activity is the cause of the closing.
  • The window must be a GUI (must display a graphical window that contains the visible exit method).
  • The visual method needs to be something the user could do if it wasn't done automatically. Explain what needs to be changed in the code for the user to be able to do this (Thanks to Iszi).
  • The program must close if there is no interference from the user, but if the user interferes, then it does not need to close automatically.
  • Please include an explanation of what it is that causes the program to close.

Example: a window containing a button which is programmatically clicked, running a short snippet of code that closes the program.

\$\endgroup\$

closed as too broad by Kevin Cruijssen, 12Me21, 0 ', Sriotchilism O'Zaic, F. Hauri Oct 24 '17 at 5:49

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    \$\begingroup\$ I'd suggest that, for programs not visible enough to be seen by a human, answers should include mention of what should be changed in the code (adding/increasing timer values, etc. - but not fundamentally changing its functionality) in order to demonstrate to a human that it actually does something visual. \$\endgroup\$ – Iszi Dec 9 '13 at 16:37
  • 1
    \$\begingroup\$ Should this be code golf or a popularity contest? \$\endgroup\$ – Kevin Mar 30 '14 at 22:56
  • 1
    \$\begingroup\$ I've changed my TI-BASIC answer to a compiled version that is shorter than my other answer (which is currently accepted). I'd appreciate it if you could change that :) \$\endgroup\$ – Timtech Apr 2 '14 at 13:30
  • 1
    \$\begingroup\$ I'm curious why this question is being DVd and VTCd. For one, this has an objective winning criterion; it's a [code-golf]. I can understand that this isn't the best question, but why is it being VTCd? \$\endgroup\$ – Justin Oct 19 '17 at 18:19
8
\$\begingroup\$

TI-Basic, 3 bytes

DispGraph:1

hex: 31 3E DF

Explanation

DispGraph Displays the graph (a graphical window)

:1 Simulates a press of 1 (by storing 1 to Ans at the last step of a program), which takes the calculator back to the home screen. A user could do the same thing.

\$\endgroup\$
  • 2
    \$\begingroup\$ GTB is kind of stupid considering that the symbols for each command are stored a 2-byte values. \$\endgroup\$ – TheDoctor Mar 30 '14 at 14:40
  • \$\begingroup\$ Concurred, I (from inspection using CalcSys) would count as 6(perhaps 4, not sure if all OSs use single-byte tokens for : and 1). Filesystem overhead and tables are obviously not included in the count. \$\endgroup\$ – ζ-- Apr 2 '14 at 10:22
  • 2
    \$\begingroup\$ What do you mean by compiled? TI-BASIC is interpreted. \$\endgroup\$ – Jakob Oct 19 '17 at 3:43
  • \$\begingroup\$ @Jakob Back then I was more confused about how TI-Basic worked. What I should have said is the source is 3 1-byte tokens. Let me fix this answer \$\endgroup\$ – Timtech Oct 19 '17 at 12:29
  • \$\begingroup\$ @Jakob There we go. I think back then we were scoring TI-Basic programs by ascii byte count rather than tokens \$\endgroup\$ – Timtech Oct 19 '17 at 12:31
10
\$\begingroup\$

Ruby with Shoes, 110

Shoes.app{button('Close'){exit}
p=para
t=Time.now
animate{u=(t-Time.now).to_i+10
exit if u<0
p.text=' '*u+?<}}

Makes a little arrow that pushes a "Close" button. (Pushing the close button manually also closes the window.)

screenshot

\$\endgroup\$
9
\$\begingroup\$

Windows Batch, 4 bytes

Save the following program to a .bat file in your user folder (C:\Users\username):

Exit

When executed from the Start, Run prompt, a new window opens, types the command Exit and executes it.

\$\endgroup\$
  • 1
    \$\begingroup\$ "The window must be a GUI (must display a graphical window that contains the visible exit method)." - it's arguable if your window contains the visible exit method, I'd say it doesn't. \$\endgroup\$ – gronostaj Mar 31 '14 at 11:35
  • 4
    \$\begingroup\$ @gronostaj It has an X in the top-right corner. \$\endgroup\$ – Seiyria Mar 31 '14 at 18:51
  • 1
    \$\begingroup\$ Ah, I see - you're exploiting the rules. There is a visible method to exit and user can do the same thing program does, but those are two different methods to terminate it. That's clever, +1. \$\endgroup\$ – gronostaj Mar 31 '14 at 19:41
4
\$\begingroup\$

JavaScript: 133 117

(You need to allow popups in your web browser for this to work)

Code-golfed:

(function(){w=window.open(),d=999,i=setInterval(function(){w.resizeTo(d-=9,d),d<0&&(clearInterval(i),w.close())})})()

Source: http://jsfiddle.net/gt2t8/2/

\$\endgroup\$
  • \$\begingroup\$ Why does it resize? \$\endgroup\$ – Justin Dec 8 '13 at 3:05
  • \$\begingroup\$ @Quincunx do this in some visually apparent manner. Like the "arm" that pushes the switch in the machine, the program must use some visual method in the GUI to close itself. \$\endgroup\$ – user1886419 Dec 8 '13 at 3:07
  • 1
    \$\begingroup\$ reduced to 117 chars: (function(){w=window.open(),d=999,i=setInterval(function(){w.resizeTo(d-=9,d);if(d<0)clearInterval(i),w.close()})})() \$\endgroup\$ – Griffin Dec 8 '13 at 4:20
  • \$\begingroup\$ @Griffin thanks! Updated with your suggestions \$\endgroup\$ – user1886419 Dec 8 '13 at 4:46
  • 1
    \$\begingroup\$ One that I can run without leaving the page. Awesome. \$\endgroup\$ – Seiyria Mar 31 '14 at 18:51
4
\$\begingroup\$

Golf-Basic 84, 5 4

g`:1

Display the graph, simluate a press of 1, closing the graph and returning home.

\$\endgroup\$
  • \$\begingroup\$ Does this do the same as your other answer? \$\endgroup\$ – Justin Dec 12 '13 at 7:58
  • \$\begingroup\$ @Quincunx Yes, it does. \$\endgroup\$ – Timtech Dec 12 '13 at 15:42
2
\$\begingroup\$

x86 / Win32 assembly (337 310 271 bytes)

.586
.model flat
option casemap:none
include kernel32.inc
include windows.inc
include user32.inc
i textequ <invoke>
.code
s:i CreateThread,0,0,$+46,0,0,0
i MessageBox,0,$,$,0
i ExitProcess,0
i Sleep,999
i FindWindow,0,$
i PostMessage,eax,256,13,0
ret
END s

Assembles with MASM32 (ml /c /coff /Gz /I<include path> test.asm / link /SUBSYSTEM:WINDOWS /LIBPATH:<library path> test.obj kernel32.lib user32.lib).

It creates a MessageBox with an "OK" button, and a thread that simulates a carriage return press from the user after 999 ms.

The $ is substituted with the address of the beginning of the code section by the assembler/linker. The first instruction is a push byte 0 (implicitly, since it's generated by the invoke), which is encoded as 6A 00, which equals the null-terminated string "j". I take advantage of this when calling MessageBox and FindWindow.

\$\endgroup\$
  • \$\begingroup\$ Is the assembly 271 bytes, or is that the size of the machine code? \$\endgroup\$ – 12Me21 Oct 19 '17 at 14:00
1
\$\begingroup\$

Bash with X Window System, 10 chars

xterm -e :

Open an xterm window, run the bash no-op :, after which the xterm window closes.

If you want to see the useless window for a second, you can change the : to sleep 1:

xterm -e sleep 1
\$\endgroup\$
1
\$\begingroup\$

Tcl/Tk, 131

grid [button .b -command exit]
event generate .b <Button-1> -warp 1 -x 5 -y 5
event generate .b <ButtonRelease-1> -warp 1 -x 5 -y 5

Tcl/Tk, 136

grid [button .b -command exit]
event generate .b <ButtonPress-1> -warp 1 -x 5 -y 5
event generate .b <ButtonRelease-1> -warp 1 -x 5 -y 5

It needs to be ran on an interactive shell, line by line and user can not move the mouse between.

  1. Application starts

enter image description here

  1. Button whose behaviour is to close the app is added to the app window

enter image description here

  1. Generate an event that presses down the mouse on the button — Altough the cursor is not visible in the screenshot it is over the button; it is visible the buttonhas been pressed because it now sunken in, and before it was embossed out.

enter image description here

  1. Finally generate an event that releases the mouse button up.

    a. Image before really sending it (before pressing Enter) enter image description here

    b. After Enter the interactive shell and the app windows just disappeared. enter image description here

Note to tcl'ers: Tried to do the same directly on the window's X Close button using:

event generate . <ButtonPress-1> -warp 1 -x 175 -y -10
event generate . <ButtonRelease-1> -warp 1 -x 175 -y -10

but I was not successful.

\$\endgroup\$
0
\$\begingroup\$

Bash - echo (50 bytes)

Not golfed, 54 bytes:

s=sleep;echo -n \>\\;$s 1;echo -ne "\b\b >/";$s 1;echo

Golfed, 50 bytes

I can't exactly display the golf version here because the backspace characters actually backspace. For the golf version, change both of the "^H" to single backspace (^H) characters:

s=sleep;echo -n \>\\;$s 1;echo -n ^H^H \>/;$s 1;echo

Notes:

  • The activity is visible for 2 seconds.

  • It doesn't use a window manager or anything of that sort, but I count the ASCII art as a "gui". If you are running the command in a terminal window, which is now the usual case, the activity is displayed in that window. It does not open up a new window.

  • The user can close the program sooner than the automatic close by hitting "CTRL-C" within 2 seconds of starting the program. Users who are more comfortable using their GUI can put their cursor on the little "X" in the corner of the terminal window, quickly, and "click" it.

  • The program closes after 2 seconds if there is no interference from the user. The user can only cause it to close sooner.

  • What causes the program to close is the completion of the final "echo".

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.