The Most Useless Program EVER!

8

4

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.

Justin

Posted 2013-12-07T01:01:02.283

Reputation: 19 757

Question was closed 2017-10-24T05:49:13.670

2I'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. – Iszi – 2013-12-09T16:37:45.940

1I'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? – Justin – 2017-10-19T18:19:28.053

1Should this be code golf or a popularity contest? – Kevin – 2014-03-30T22:56:43.363

1I'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 :) – Timtech – 2014-04-02T13:30:07.577

Answers

8

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.

Timtech

Posted 2013-12-07T01:01:02.283

Reputation: 12 038

2What do you mean by compiled? TI-BASIC is interpreted. – Jakob – 2017-10-19T03:43:12.427

@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 – Timtech – 2017-10-19T12:29:56.197

@Jakob There we go. I think back then we were scoring TI-Basic programs by ascii byte count rather than tokens – Timtech – 2017-10-19T12:31:45.780

Oh yeah, I wondered if the age of the answer had something to do with it. Thanks! – Jakob – 2017-10-19T15:31:10.260

2GTB is kind of stupid considering that the symbols for each command are stored a 2-byte values. – TheDoctor – 2014-03-30T14:40:24.233

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. – Reinstate Monica - ζ-- – 2014-04-02T10:22:18.553

10

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

Doorknob

Posted 2013-12-07T01:01:02.283

Reputation: 68 138

9

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.

Hand-E-Food

Posted 2013-12-07T01:01:02.283

Reputation: 7 912

1"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. – gronostaj – 2014-03-31T11:35:56.003

4@gronostaj It has an X in the top-right corner. – Seiyria – 2014-03-31T18:51:21.183

1Ah, 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. – gronostaj – 2014-03-31T19:41:59.597

4

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/

user1886419

Posted 2013-12-07T01:01:02.283

Reputation: 1 015

Why does it resize? – Justin – 2013-12-08T03:05:41.290

@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. – user1886419 – 2013-12-08T03:07:52.337

1reduced to 117 chars: (function(){w=window.open(),d=999,i=setInterval(function(){w.resizeTo(d-=9,d);if(d<0)clearInterval(i),w.close()})})() – Griffin – 2013-12-08T04:20:17.340

@Griffin thanks! Updated with your suggestions – user1886419 – 2013-12-08T04:46:42.580

1One that I can run without leaving the page. Awesome. – Seiyria – 2014-03-31T18:51:57.000

Always think JS answers should get -75, so I don't have to leave... and then +50 for having to disable popups – Dean Meehan – 2014-04-02T14:39:56.110

4

Golf-Basic 84, 5 4

g`:1

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

Timtech

Posted 2013-12-07T01:01:02.283

Reputation: 12 038

Does this do the same as your other answer? – Justin – 2013-12-12T07:58:45.183

@Quincunx Yes, it does. – Timtech – 2013-12-12T15:42:38.560

2

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.

Michael

Posted 2013-12-07T01:01:02.283

Reputation: 231

Is the assembly 271 bytes, or is that the size of the machine code? – 12Me21 – 2017-10-19T14:00:12.557

1

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.

sergiol

Posted 2013-12-07T01:01:02.283

Reputation: 3 055

1

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

Digital Trauma

Posted 2013-12-07T01:01:02.283

Reputation: 64 644

0

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".

Glenn Randers-Pehrson

Posted 2013-12-07T01:01:02.283

Reputation: 1 877