ttscoff / bunch

Documentation repository for Bunch.app
https://bunchapp.co
116 stars 5 forks source link

Delay Quitting App Requires Delayed Snippet #306

Closed aarblaster closed 1 year ago

aarblaster commented 1 year ago

I am not sure if this is a bug, edge case or expected behaviour. Apologies if I've just misunderstood the documentation! I'm running Bunch v1.4.13 on a MacBook Pro 14" (2021, M1 Pro, 32GB RAM) running MacOS v14.0 (23A344). I'm using Bunch in the default Serial mode.

I wanted to delay an app being quit on closing the Bunch, where that app had opened in the bunch. In order to allow an AppleScript to run on closing first. I have replicated the behaviour down to the simplest version. In this simplified version, using Drafts and a simple AppleScript, the app still quits immediately on a new (empty) bunch opening or the bunch being toggled off.

---
title: Test
---

// Open the app, making sure it doesn't quit on close using `%`
%Drafts

// On Close do the AppleScript, then after 10 seconds quit the app.
!* say "Hello, world"
!!!Drafts ~10

I attempted using !(pause 10) after the AppleScript, but that had the same effect. The behaviour persists regardless what happens in the place of the AppleScript.

The solution I got to work was:

---
title: Test
---

// Open the app, making sure it doesn't quit on close using `%`
%Drafts

// On Close do the AppleScript, then after 10 seconds quit the app.
!* say "Hello, world"
!<<#OnCloseApps ~10

___
#[OnCloseApps]
!Drafts

Is this expected behaviour, or should simply including !!!Drafts ~10 have resulted in the app quitting after 10 seconds? Using the snippet is a fine solution and absolutely works even in my final bunch (managing Xcode runs). Just took my newish programming brain a while to troubleshoot. Thanks! :)

ttscoff commented 1 year ago

On close doesn't deal well with pauses, I'm afraid, I'm kind of surprised that the snippet version works... The other solution would be to have your AppleScript quit Drafts after it runs with "tell application Drafts to quit."

-Brett

On 22 Oct 2023, at 0:07, Anthony Arblaster wrote:

I am not sure if this is a bug, edge case or expected behaviour. Apologies if I've just misunderstood the documentation! I'm running Bunch v1.4.13 on a MacBook Pro 14" (2021, M1 Pro, 32GB RAM) running MacOS v14.0 (23A344). I'm using Bunch in the default Serial mode.

I wanted to delay an app being quit on closing the Bunch, where that app had opened in the bunch. In order to allow an AppleScript to run on closing first. I have replicated the behaviour down to the simplest version. In this simplified version, using Drafts and a simple AppleScript, the app still quits immediately on a new (empty) bunch opening or the bunch being toggled off.

---
title: Test
---

// Open the app, making sure it doesn't quit on close using `%`
%Drafts

// On Close do the AppleScript, then after 10 seconds quit the app.
!* say "Hello, world"
!!!Drafts ~10

I attempted using !(pause 10) after the AppleScript, but that had the same effect. The behaviour persists regardless what happens in the place of the AppleScript.

The solution I got to work was:

---
title: Test
---

// Open the app, making sure it doesn't quit on close using `%`
%Drafts

// On Close do the AppleScript, then after 10 seconds quit the app.
!* say "Hello, world"
!<<#OnCloseApps ~10

___
#[OnCloseApps]
!Drafts

Is this expected behaviour, or should simply including !!!Drafts ~10 have resulted in the app quitting after 10 seconds? Using the snippet is a fine solution and absolutely works even in my final bunch (managing Xcode runs). Just took my newish programming brain a while to troubleshoot. Thanks! :)

-- Reply to this email directly or view it on GitHub: https://github.com/ttscoff/bunch/issues/306 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

aarblaster commented 1 year ago

Hey @ttscoff, No worries at all β€” as long as it's not just me!

Moving it into an AppleScript is a good idea. I tried to get that to work in my original and couldn't get it do wait long enough. That feels like a nicer solution so I might have a little research into a more robust way of waiting.

My production bunch uses AppleScript to stop Xcode build and run. Incase I forget to stop it before moving onto my next work layout.

Thanks for the speedy reply! And for Bunch. Can't imagine my Mac without it now.

aarblaster commented 1 year ago

Totally solved it with an AppleScript! It really didn't like Heredoc AppleScript on close but simply moving to an external AppleScript in the Bunch folder and inserting !* QuitXcodeBunch.scpt resolved it no problem. πŸ‘

Must have been an error on my part why it didn't work like this before.

ttscoff commented 1 year ago

Glad it’s working!

Thanks, Brett On Oct 22, 2023 at 9:23β€―AM -0500, Anthony Arblaster @.***>, wrote:

Totally solved it with an AppleScript! It really didn't like Heredoc AppleScript on close but simply moving to an external AppleScript in the Bunch folder and inserting !* QuitXcodeBunch.scpt resolved it no problem. πŸ‘ Must have been an error on my part why it didn't work like this before. β€” Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>