ShareShortcuts
Fork “BT disconnect”

Built something new on top of this Shortcut? Share it as a fork: it becomes a Shortcut of your own, which you manage, and both pages link to each other so weplaydr gets credit.

  1. 1Get the Shortcut and change it in the Shortcuts app. Give it a name of its own.
  2. 2Share it from the Shortcuts app and copy the iCloud link.
  3. 3Come back here, paste the link and describe what is different, e.g. “Added a step that uses Apple Intelligence to personalise the text.”
Downloads
13K
Saved
1
Actions
34
Category
Routines
Version
1.1
Language
EN

Preview

This is the companion of several Shortcuts that automatically TurnOff Bluetooth after 60seconds iff no device connects. These shortcuts are in pairs. Turning off Bluetooth is not for everyone, but I prefer Bluetooth usually off, not remain on forever. For help contact me at game@telus.net

What's New

Version 1.1

Semaphores are now folders not files to circumvent an iOS bug pertaining to disappearing files

Version History
1.1 Sep 24, 2025

Semaphores are now folders not files to circumvent an iOS bug pertaining to disappearing files

1.0 Aug 4, 2025

First release

What it does

34 actions
  1. Comment
    To begin using this shortcut, You MUST manually create a folder on your iPhone named Shortcuts/Semaphore Contact me for more info [email protected]
  2. Comment
    NOTE: To make this shortcut work, YOU MUST MANUALLY create a folder on your iPhone named Shortcuts/Semaphore/Bluetooth Here, this shortcut and a companion shortcut will create & delete LockFiles.
  3. Comment
    202501Jan24-1500h IFF the disconnected device was unmanaged, do not give 1minute grace period; simple check whether or not to auto-off BlueTooth
  4. Comment
    Whenever device <named passed in> is disconnected, delete a BTdevice lockfile. Return result of Test&Clear <device name>
  5. Number
  6. Comment
    20250Jan08-2000h PROVIDE [60] SIXTY SECONDS (1min) ALLOWANCE rather than dropping BlueTooth immediately.
  7. Set Variable
    ran_time
  8. Text
  9. Set Variable
    tLockDate
  10. Get Text from Input
  11. If
  12. Stop and Output
  13. Text
  14. Get File
  15. If
  16. Text
  17. Set Variable
    tLockDate
  18. Delete Files
  19. Comment
    ^^^^ Above, delete Device Lock File ASAP & immediate deletion, to permit same device to re-connect quickly.
  20. Wait
  21. Comment
    20250Jan08-2000h 1.KEEP BT ON because a fresh BT DEVICE might CONNECT in the meanwhile. expressly DELAY [60] SECONDS.
  22. Text
  23. Get Contents of Folder
  24. Count
  25. If
  26. Comment
    202411Nov26 FOR TODAY OMIT REDUNDANTLY TURNING ON BLUETOOTH, because might cause unbeknownst race condition. ⁉️
  27. Show Notification
    BT … remain … LockCreated …
  28. If
  29. Create Folder
  30. Set Bluetooth
  31. Play Sound
  32. Comment
    #### AUTO-OFF 😁 🟦🦷 #### #### IF NO DEVICE BT LOCK FILES EXIST, 60second delay helps avoid connection RACE CONDITION. AUTO-TURN OFF BLUETOOTH XMIT’R
  33. Show Notification
    Bluetooth is now Off …
  34. Get Variable

View as code
Beta

Every action of this Shortcut written out as Cherri, a programming language for Shortcuts. Great for learning how it works.

#include 'actions/text'
#define color taupe

/*
To begin using this shortcut,

You MUST manually create a folder on your iPhone named Shortcuts/Semaphore

Contact me for more info
[email protected]
*/
/*
NOTE: To make this shortcut work, YOU MUST MANUALLY create a folder on your iPhone named Shortcuts/Semaphore/Bluetooth

Here, this shortcut and a companion shortcut will create & delete LockFiles.

*/
// 202501Jan24-1500h  IFF the disconnected device was unmanaged, do not give 1minute grace period; simple check whether or not to auto-off BlueTooth

/*
Whenever device <named passed in> is disconnected, delete a BTdevice lockfile.
Return result of Test&Clear <device name>
*/
const nSeconds_Wait = 60
// 20250Jan08-2000h PROVIDE  [60] SIXTY SECONDS (1min) ALLOWANCE rather than dropping BlueTooth immediately.

@ran_time = CurrentDate
@tLockDate = "{@ran_time}"
const INdevice = getText(ShortcutInput)

if !INdevice {
	mustOutput("-2\nExpected name of bluetooth device. Exiting.", "-2\nExpected name of bluetooth device. Exiting.")
}
const BTfilename = "BT{INdevice}_sema"
const BTlockfile = getFile(BTfilename, false)

if BTlockfile['File Path'] {
	@tLockDate = "{BTlockfile['Creation Date']}"
	deleteFiles(BTlockfile, true)
	// ^^^^ Above, delete Device Lock File ASAP & immediate deletion, to permit same device to re-connect quickly.

}
wait(nSeconds_Wait)
/*
20250Jan08-2000h 1.KEEP BT ON because a fresh BT DEVICE might CONNECT in the meanwhile. 

expressly DELAY  [60] SECONDS.

 

*/
const Time_Stamp = "{CurrentDate}"
const GetContentsOfFolder = getFolderContents()
const countFolderDevicesRemaining = count(GetContentsOfFolder['File Path'])

if countFolderDevicesRemaining > 0 {
	// 202411Nov26 FOR TODAY OMIT REDUNDANTLY TURNING ON BLUETOOTH, because might cause unbeknownst race condition. ⁉️

	showNotification(" BT {countFolderDevicesRemaining} remain {Textran_time}\n\nLockCreated {@tLockDate}", "✅ {INdevice} released.", false)
} else {
	createFolder("BTOff_flag")
	setBluetooth(0)
	playSound(nil)
	/*
	#### AUTO-OFF 😁  🟦🦷 ####
	
	#### IF NO DEVICE BT LOCK FILES EXIST, 60second delay helps avoid connection RACE CONDITION. AUTO-TURN OFF BLUETOOTH XMIT’R
	
	*/
	showNotification("      Bluetooth is now Off  {Textran_time}", "ℹ️ {INdevice} was last BT device", false)
}
// TODO: Get Variable not supported: Assign variable here to 'countFolderDevicesRemaining'.
Open in Cherri Playground Decompiled with cherri 2.3.0 (GPL-2.0). May need small fixes before it compiles.

Ratings & Reviews

Write a Review
–
out of 5
★★★★★
★★★★
★★★
★★
★
0 ratings

No reviews yet. Be the first to share what you think!

Advertisement

More by weplaydr

See All

You Might Also Like

See All
Advertisement