Window with transparent background

I am very new with AppleScript and I am discovering what it is possible and what not. I would like to create a watch on the desktop with the hour and minutes: 12:04. With no background, just the time. Is that possible with AppleScript?

Hi. Creating a complex user interface such as a watch dial with alpha channel transparency isn’t possible with AppleScript alone. You could hack something together that simulates your desired result; for example, use an image editor to composite a watch overlay on your desktop background, load the image, position a folder within the static face and update its name to the time.

How about this? We can display transparent alert dialog or transparent window.
We can make timer interrupt finction by AppleScript.

-- Created 2019-07-08 by Takaaki Naganoya
-- 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property |NSURL| : a reference to current application's |NSURL|
property NSFont : a reference to current application's NSFont
property NSView : a reference to current application's NSView
property NSAlert : a reference to current application's NSAlert
property NSColor : a reference to current application's NSColor
property NSTextView : a reference to current application's NSTextView
property NSScrollView : a reference to current application's NSScrollView
property NSRunningApplication : a reference to current application's NSRunningApplication
property NSModalPanelWindowLevel : a reference to current application's NSModalPanelWindowLevel

property returnCode : 0

--Get Self Source Code (a kind of joke)
set asStr to time string of (current date)
set paramObj to {myMessage:"Main Message", mySubMessage:"Sub information", mes1:(asStr), mesWidth:400, mesHeight:100, fontName:"HiraginoSans-W3", fontSize:80.0}

--my dispTextViewWithAlertdialog:paramObj--for debug
my performSelectorOnMainThread:"dispTextViewWithAlertdialog:" withObject:paramObj waitUntilDone:true


on dispTextViewWithAlertdialog:paramObj
	--Receive Parameters
	set aMainMes to (myMessage of paramObj) as string --Main Message
	set aSubMes to (mySubMessage of paramObj) as string --Sub Message
	set mesStr to (mes1 of paramObj) as string --Text Input field 1 Label
	set aWidth to (mesWidth of paramObj) as integer --TextView width
	set aHeight to (mesHeight of paramObj) as integer --TextView height
	set aFontName to (fontName of paramObj) as string --TextView font name
	set aFontSize to (fontSize of paramObj) as real --TextView font size
	
	--Detect Dark Mode
	set dMode to retLIghtOrDark() of me
	if dMode = true then
		set tvCol to 1
		set tvAlpha to 1.0
		set bCol to 0.1
		set bAlpha to 0.0
	else
		set tvCol to 1
		set tvAlpha to 1.0
		set bCol to 1
		set bAlpha to 0.0
	end if
	
	-- Create a TextView with Scroll View
	set aScroll to NSScrollView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, aWidth, aHeight))
	set aView to NSTextView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, aWidth, aHeight))
	aView's setRichText:true
	aView's useAllLigatures:true
	aView's setTextColor:(NSColor's cyanColor()) --cyanColor
	aView's setFont:(NSFont's fontWithName:aFontName |size|:aFontSize)
	set aColor to NSColor's colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:(tvAlpha)
	aView's setBackgroundColor:aColor
	aView's setOpaque:(false)
	aView's setString:mesStr
	aScroll's setDocumentView:aView
	aView's enclosingScrollView()'s setHasVerticalScroller:true
	
	-- set up alert
	set theAlert to NSAlert's alloc()'s init()
	tell theAlert
		--for Messages
		its setMessageText:(aMainMes)
		its setInformativeText:(aSubMes)
		
		--for Buttons
		its addButtonWithTitle:"OK"
		its addButtonWithTitle:"Cancel"
		
		--Add Accessory View
		its setAccessoryView:(aScroll)
		
		--for Help Button
		its setShowsHelp:(true)
		its setDelegate:(me)
		
		set myWindow to its |window|
	end tell
	
	myWindow's setOpaque:(false)
	myWindow's setBackgroundColor:(NSColor's colorWithCalibratedWhite:(bCol) alpha:(bAlpha))
	myWindow's setLevel:(NSModalPanelWindowLevel)
	
	-- show alert in modal loop
	NSRunningApplication's currentApplication()'s activateWithOptions:0
	my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true
	if (my returnCode as number) = 1001 then error number -128
end dispTextViewWithAlertdialog:


on doModal:aParam
	set (my returnCode) to aParam's runModal()
end doModal:


on alertShowHelp:aNotification
	display dialog "Help Me!" buttons {"OK"} default button 1 with icon 1
	return false
end alertShowHelp:


--Detect Dark Mode dark:true、Light:false
on retLIghtOrDark()
	set curMode to (current application's NSUserDefaults's standardUserDefaults()'s stringForKey:"AppleInterfaceStyle") as string
	return (curMode = "Dark") as boolean
end retLIghtOrDark

Model: MacBook Pro 2012
AppleScript: 2.7
Browser: Safari 13.0.1
Operating System: macOS 10.14

Hi maro.

I’ve wrapped your script code in MacScripter’s special [applescript] and [/applescript] tags, so that it’s shown in a box with a clickable link, as above. (The link opens the code in Script Editor, or in Script Debugger if you have the latter set to respond to “applescript://” URLs.) Would you mind using these tags yourself when posting AppleScript and or ASObjC code? There’s an “Applescript” button for them just above the text field when you enter your post.

Thanks NG. I memorize it.

I wrote a simple transparent clock. How about this?

http://piyocast.com/as/archives/7534

Running Maro’s transparent clock script at http://piyocast.com/as/archives/7534, I was unable to close Maro’s window or quit Maro’s transparent clock script, by clicking either button. This required a force quit of the application.
What code should I insert into the script to empower a button to close the window and the script, without having to rely on force quitting?

AS I wrote comment to your post on my blog, it depends on the runtime environment.

Script Editor: Can receive user's mouse click event and get focus
Script Debugger: Can not
AppleScript applet: Can receive
Script Menu: Can not
osascript: Can not

I don’t know how to arrange the runtime environment.

Model: MacBook Pro 2012
AppleScript: 2.7
Browser: Safari 13.0.1
Operating System: macOS 10.14