Thanks. For some reason, the action I want to take (modify note description
and return), or at any rate, something in the commented out block below, causes
the script to hang if that circumstance (removing AC while backup running)
arises. But the continued presence of the volume icon on the desktop is enough
visual feedback, that I'm ok with what I have now.
The apparent quirkiness and debugging difficulty, on top of the pseudo-natural
language style, makes AppleScript rather challenging for me. :-)
using terms from application "Growl"
on evaluate notification with notification
set backupVolume to "LaCie"
set mountedMessage to backupVolume & " Mounted"
set unmountedMessage to backupVolume & " Unmounted"
if notification's app name equals "HardwareGrowler" then
if notification's note title equals "On Battery Power" then
set TimeMachineIsRunning to do shell script "tmutil status"
if TimeMachineIsRunning contains "Running = 0;" then
tell application "Finder"
if disk backupVolume exists then eject disk backupVolume
end tell
-- The bit below seems to make the script hang. Still-present
-- volume icon will have to be enough feedback.
(*
else
set alertMessage to ¬
"\rWarning: Time Machine backup in progress, " & ¬
"cannot auto-eject backup volume " & backupVolume & "."
set notification's note description to ¬
notification's note description & alertMessage
return {notification return:notification}
*)
end if
else if notification's note title equals mountedMessage then
do shell script "sudo tmutil enable;sudo tmutil disablelocal"
else if notification's note title equals unmountedMessage then
do shell script "sudo tmutil disable;sudo tmutil disablelocal"
end if
end if
end evaluate notification
end using terms from
> On Apr 12, 2017, at 13:54, Daniel Siemer <[email protected]> wrote:
>
> Ill answer the other question first, yes an explicit return is needed to
> modify a notification via rules.
> After modifying the description on notification do this:
> return { notification return: notification }
>
> (from our scripting dictionary, only title, description, icon, sticky, and
> priority are modifiable)
>
> Growl invokes the rules script using by getting an NSUserScriptTask for the
> Rules.scpt file (and only if it comes back as an NSUserApplescriptTask).
> It's executed using our event descriptors, but the actual execution is done
> outside our process and sandbox. Compiled AppleScript scripts should work
> with the right extension, but I have never tried working with other OSA
> languages such as javascript. I will look at seeing if I can get a hello
> world sample JXA script working, but not holding my breath.
>
> The original intent was to allow true unix scripting for rules with json
> inputs/returns, but there were problems with the NSUserUnixTask (I think I
> was having problems getting return values).
>
> NoteType is visible to the user under an application's entry in
> "Applications" in preferences. On the notifications tab for the application,
> on each note at the bottom of its preferences is a label labeled "Rule Type:"
> Note that some apps use long-ish names here, just drag select to select it
> all before copying.
>
> On Tuesday, April 11, 2017 at 5:26:54 PM UTC-5, rlhamil wrote:
> Well, to answer one of my own questions, here are what the properties look
> like for a HardwareGrowler mount or unmount notification (omitting the
> note icon, which I didn't think made sense to write out as text!) for
> a volume in this case named "LaCie":
>
> host: localhost
> app name: HardwareGrowler
> note type: VolumeMounted
> note title: LaCie Mounted
> note description: Click to open
> sticky: false
> priority: normal
>
> host: localhost
> app name: HardwareGrowler
> note type: VolumeUnmounted
> note title: LaCie Unmounted
> note description:
> sticky: false
> priority: normal
>
>
> Here's my script again, with the ability to, when AC power is removed,
> auto-eject the backup disk if a Time Machine backup is not currently in
> progress. The action to take if a backup IS running has not yet been
> exercised. :-) (that relates to my other question: whether an explicit
> return of the notification is needed to pass back a modified property - some
> help with that please?)
>
> The volume name is now in a variable; assuming a single external backup drive
> on a laptop, this might work in other cases, by just changing the value of
> backupVolume appropriately.
>
> I _hate_ debugging AppleScript, it doesn't tell you where an error is, only
> that there is one. I got around that with osascript -i and pasting in a
> single line at a time; but there's got to be a better way (short of buying
> Late Night Software's expensive script debugger). Still, once it's working,
> it's kind of nice to just do one thing and have all the rote followup happen
> by itself. :-)
>
> using terms from application "Growl"
> on evaluate notification with notification
> -- change value below as needed
> set backupVolume to "LaCie"
> set mountedMessage to backupVolume & " Mounted"
> set unmountedMessage to backupVolume & " Unmounted"
> if notification's app name equals "HardwareGrowler" then
> if notification's note title equals "On Battery Power" then
> set TimeMachineIsRunning to do shell script "tmutil status"
> if TimeMachineIsRunning contains "Running = 0;" then
> tell application "Finder"
> if disk backupVolume exists then eject disk backupVolume
> end tell
> else
> set alertMessage to ¬
> "\rWarning: Time Machine backup in progress, " & ¬
> "cannot auto-eject backup volume " & backupVolume & "."
> set notification's note description to ¬
> notification's note description & alertMessage
> end if
> else if notification's note title equals mountedMessage then
> do shell script "sudo tmutil enable;sudo tmutil disablelocal"
> else if notification's note title equals unmountedMessage then
> do shell script "sudo tmutil disable;sudo tmutil disablelocal"
> end if
> end if
> -- absent an explicit return, defaults are used
> end evaluate notification
> end using terms from
>
>
>
>
>
>> On Apr 10, 2017, at 15:11, Richard L. Hamilton <[email protected]
>> <javascript:>> wrote:
>>
>> How does Growl invoke the ~/Library/Application
>> Scripts/com.Growl.GrowlHelperApp/Rules.scpt file? Notwithstanding the
>> ".scpt" suffix, it works fine if Rules.scpt has plain text AppleScript in
>> it; but if it could have a "compiled" script in there instead, anything
>> listed by osalang could be used; for Yosemite and later, that includes
>> JavaScript.
>>
>> And that doesn't even count having the script use "do shell script" not only
>> to take some unusual action, but by passing the interesting properties of
>> the notification, give the script some ability to choose what to do about
>> it. Quoting the properties safely yet keeping them separate while passing
>> them might be a tricky proposition, and not one I wish to explore right now.
>> :-)
>>
>> What are examples of what the "note type" property might have in it, anyway?
>> I don't see that field shown in the history, and didn't need it in this
>> case, so I didn't fool with a temporary script just to see what all the
>> properties looked like.
>>
>> One more question: if I want to modify a property (the note description, in
>> what I have in mind, by appending some text to it), do I have to explicitly
>> return the notification, or will the default behavior see the change? I saw
>> an example of doing things when switching to battery power, and I think I
>> can hook in some code that, when AC is removed, checks if a backup is
>> running, and if not, ejects the backup volume (if it's mounted). If a
>> backup _is_ running, I may want to append "\r Note: cannot auto-eject backup
>> volume" to the notification text for going on battery; otherwise, I ought to
>> generate an additional visual indication ("display alert", or can I send an
>> additional notification within the rules script, without messing up the
>> notification I'm responding to? and wouldn't I have to make up a bogus
>> application name for that?").
>>
>>> On Apr 10, 2017, at 11:59, Chris Forsythe <[email protected] <javascript:>>
>>> wrote:
>>>
>>> I believe if you want something more esoteric you can execute a script in a
>>> different language. I'm not sure on how to accomplish it but I'm sure the
>>> googles do. I'm glad this is headed in the direction you need though, it's
>>> definitely something we added with this sort of usage in mind.
>>>
>>> On Fri, Apr 7, 2017 at 6:40 PM, Richard L. Hamilton <[email protected]
>>> <javascript:>> wrote:
>>> Well, this seems to do what I want, as near as possible - enable or disable
>>> Time Machine depending on whether the backup drive is mounted, and in
>>> either case (since this doesn't seem to be remembered!) turn off local
>>> snapshots, which seem to me not a great idea with an SSD, at least if one
>>> doesn't need such a guarantee that backups will be particularly recent.
>>>
>>> using terms from application "Growl"
>>> on evaluate notification with notification
>>> if notification's app name equals "HardwareGrowler" then
>>> if notification's note title equals "LaCie Mounted" then
>>> do shell script "sudo tmutil enable;sudo tmutil disablelocal"
>>> else if notification's note title equals "LaCie Unmounted" then
>>> do shell script "sudo tmutil disable;sudo tmutil disablelocal"
>>> end if
>>> end if
>>> -- absent an explicit return, defaults are used
>>> end evaluate notification
>>> end using terms from
>>>
>>> This does assume that the account using it is able to do a "sudo" without
>>> password; other than that and the name of the volume mounted or unmounted,
>>> it's probably fairly generic for such a use. Having the Script Editor show
>>> me Growl's dictionary, along with looking at actual recent examples in the
>>> Growl log, provided the information I needed.
>>>
>>> AppleScript was clearly descended from something intended to appeal to
>>> non-programmers; as such, it makes my head hurt a bit; but for something
>>> small that can't as easily be done any other way, I guess I can live with
>>> that. :-)
>>>
>>>> On Mar 27, 2017, at 14:13, Chris Forsythe <[email protected] <javascript:>>
>>>> wrote:
>>>>
>>>> It's fine I think you're golden with Growl given it has two events. I'd
>>>> really suggest the applescript rules. Think of applescript as just a
>>>> different language and don't try to make it a 1:1 comparison to say bash
>>>> or python. It's more like plain talking so to speak.
>>>>
>>>> Anyhow you could write a script to watch for the contents for the
>>>> different things you want to watch for. The very end of our documentation
>>>> talks about how to execute a shell script from there:
>>>>
>>>> http://growl.info/documentation/applescript-rules
>>>> <http://growl.info/documentation/applescript-rules>
>>>>
>>>> I think this is going to handle what you need and be fairly simple once
>>>> you've got it worked out in your head and laid out. If you read it and run
>>>> into issues once making the script reply back here.
>>>>
>>>>
>>>> On Sat, Mar 25, 2017 at 2:27 AM, Richard L. Hamilton <[email protected]
>>>> <javascript:>> wrote:
>>>> (apologies if this is a dupe; it looked like it failed before, when I had
>>>> a cc to [email protected] <javascript:> when my membership
>>>> hasn't been approved yet)
>>>>
>>>> I'd like to have a script run
>>>> sudo tmutil enable
>>>> when /Volumes/LaCie is mounted, and
>>>> sudo tmutil disable
>>>> sudo tmutil disablelocal
>>>>
>>>> when it's unmounted (I don't want local snapshots on the internal SSD, but
>>>> tmutil disablelocal doesn't seem to be remembered across reboots; it's
>>>> good enough that I have backups running when the Thunderbolt drive is
>>>> plugged in).
>>>>
>>>> Additionally, for that and any other mount/unmount not in
>>>> HardwareGrowler's exception list, I'd like the usual visual notification.
>>>>
>>>> Assume that I've tweaked /etc/sudoers or otherwise made arrangements (such
>>>> as porting Linux pam_ssh_agent_auth.so and configuring it) so that I don't
>>>> need to enter my password for sudo. And of course, the system won't let
>>>> me unmount the drive if it's in use (not counting forced unmounts), so the
>>>> script doesn't need to worry about that.
>>>>
>>>> I've never really worked with AppleScript, and have no idea how the
>>>> arguments (like whether it's a mount or unmount, and what the mount point
>>>> is) are passed, so some help would be great!
>>>>
>>>> I'd actually rather use ControlPlane than HardwareGrowler+Growl, but
>>>> ControlPlane doesn't (AFAIK) have a mount/unmount "evidence" source, and
>>>> neither HardwareGrowler nor ControlPlane seem to have a provision for
>>>> noticing the connection/disconnection of Thunderbolt devices.
>>>>
>>>> thanks...
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups
>>>> "Growl Discuss" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send an
>>>> email to [email protected] <javascript:>.
>>>> To post to this group, send email to [email protected]
>>>> <javascript:>.
>>>> Visit this group at https://groups.google.com/group/growldiscuss
>>>> <https://groups.google.com/group/growldiscuss>.
>>>> For more options, visit https://groups.google.com/d/optout
>>>> <https://groups.google.com/d/optout>.
>>>>
>>>>
>>>>
>>>> --
>>>> Chris Forsythe
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups
>>>> "Growl Discuss" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send an
>>>> email to [email protected] <javascript:>.
>>>> To post to this group, send email to [email protected]
>>>> <javascript:>.
>>>> Visit this group at https://groups.google.com/group/growldiscuss
>>>> <https://groups.google.com/group/growldiscuss>.
>>>> For more options, visit https://groups.google.com/d/optout
>>>> <https://groups.google.com/d/optout>.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Growl Discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to [email protected] <javascript:>.
>>> To post to this group, send email to [email protected]
>>> <javascript:>.
>>> Visit this group at https://groups.google.com/group/growldiscuss
>>> <https://groups.google.com/group/growldiscuss>.
>>> For more options, visit https://groups.google.com/d/optout
>>> <https://groups.google.com/d/optout>.
>>>
>>>
>>>
>>> --
>>> Chris Forsythe
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Growl Discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to [email protected] <javascript:>.
>>> To post to this group, send email to [email protected]
>>> <javascript:>.
>>> Visit this group at https://groups.google.com/group/growldiscuss
>>> <https://groups.google.com/group/growldiscuss>.
>>> For more options, visit https://groups.google.com/d/optout
>>> <https://groups.google.com/d/optout>.
>>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Growl Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/growldiscuss
> <https://groups.google.com/group/growldiscuss>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google Groups
"Growl Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/growldiscuss.
For more options, visit https://groups.google.com/d/optout.