Dialog Box Title

Hi.
I have this coding:
set theDialogText to "Warning: 10% remaining. Charge MacBook."

display dialog theDialogText buttons {"OK"} default button "OK" cancel button "OK" giving up after 1000

if gave up of result = true then

tell application "System Events"

start current screen saver

end tell

end if

When I press Run Script, a dialog box appears:

How do I:

  • make this dialog box appear ONLY when my battery drops below 10%.
  • Add a title, eg: Battery Warning.
    the title should look like the words 'Setup Sidecar' in this pic:

thanks

edit: I stole-ahem-borrowed the coding for my dialog box from someone (i forgot who, sorry). I dont know how to edit it so that it doesnt sleep - the person i borrowed it from used it as a sleep confirmation button - so i just changed the delay to 1000 so it'll never sleep.
just letting anyone who wants to know, know.
thanks

add with title "your title" after a space in the line.

Regarding the trigger when battery reaches 10%, there have been discussion so recently doing that using shell scripts. Just do quick search and you'd find it.

1 Like

Hi @rishifter
where exactly do you mean? I couldnt get it working.. can you put it in the code and send it to me so that I can copy and paste it?
Thanks very much.

Sorry, it was a little confusing. Try this

    display dialog theDialogText buttons {"OK"} default button "OK" cancel button "OK" giving up after 1000 with title "This is a title"

amazing! it worked :grin: :grin:
Now, is there a way for me to make the title in bold?
thanks

also, how do I make this only activate when my battery is below 10%?

I don't think you can format the title in anyway, I've never seen that in an AppleScript in years.

Regarding triggering the action only when battery reaches 10%, I think refer to this conversation

You must have a deja vu!

The last script pasted there seems to have the same

tell application "BetterTouchTool"
		execute_assigned_actions_for_trigger "PASTE_THE_UUID_HERE"
end tell

you can replace that UUID with the one for this one and it should work!

1 Like

haha. I made that 'Battery Triggered Button' topic, for my touchbar. I've already tried copying the code, putting the code for this in.. etc. I have no idea how to do it tho.

Can you share the code you have for the battery button on Touch Bar? We'd just need to add one line to it to make it show the dialog.

set powersource to word 4 of paragraph 1 of (do shell script "pmset -g batt")
if powersource is "AC" then
return ""
else
set batteryPercent to word 6 of paragraph 2 of (do shell script "pmset -g batt")
if batteryPercent is "100" then
return ""
else if batteryPercent is less than "11" then
tell application "BetterTouchTool"
execute_assigned_actions_for_trigger "1F9B1FAB-8AA0-4005-B330-FE5E6B8FA6A0"
end tell
set remainingminutes to word 9 of paragraph 2 of (do shell script "pmset -g batt")
return "Warning: " & batteryPercent & "% Remaining. Please charge MacBook. " & remainingminutes & " minutes until lockdown."
else
return ""
end if
end if

the uuid you see is for my trackpad to vibrate

execute_assigned_actions_for_trigger "1F9B1FAB-8AA0-4005-B330-FE5E6B8FA6A0"

Where you have this line in the code, duplicate it. And in the second one add the UUID of the named trigger you created before for bringing up the dialog. Then it will both send a haptic feedback to vibrate and also show you the dialog.

To share code like this you can use shortcut CMD+Shift+C when posting something here.

hey,
the code for the dialog box is not a named trigger. can I just use the UUID for where it is (under 'Touchbar').

I am a little confused but I think it should work. Give it a try?

I tried it, but it isnt working, and now the touchbar warning isnt working either?

Perhaps try creating a named trigger and use the UUID for that. That sounds like the simplest way.

okay, done that. now ill wait to see if it works

hi, just an update. I'm using a HUD overlay instead of the dialog box... thanks soooo much for your help though :smiley:

1 Like