Skip to content

Commit b104795

Browse files
denisarombert
authored andcommitted
Introduce new MacOSX notifier that rely on osascript instead of terminal-notifier; used as a fall-back on 10.9 and newer
1 parent ce88772 commit b104795

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ On Linux Maven Desktop Notifier uses `notify-send` and, where available, `kdialo
2121
but other compliant implementations, for instance those provided by Cinnamon and Xfce, should work just fine.
2222

2323
### Mac OS X ###
24-
On Mac OS X 10.8 or higher, Maven Desktop Notifier uses `terminal-notifier`. Installation instructions for `terminal-notifier` can be found
24+
Maven Desktop Notifier uses the Notification Center.
25+
26+
On Mac OS X 10.9 or higher, Maven Desktop Notifier uses `osascript` unless `terminal-notifier` has been installed.
27+
On Mac OS X 10.8, Maven Desktop Notifier uses `terminal-notifier`. Installation instructions for `terminal-notifier` can be found
2528
[here](https://github.com/alloy/terminal-notifier/).
2629

2730
### Windows ###

src/main/java/ro/lmn/maven/dmn/NotifierFactory.java

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import ro.lmn.maven.dmn.api.Notifier;
2424
import ro.lmn.maven.dmn.impl.LinuxNotifier;
2525
import ro.lmn.maven.dmn.impl.MacOSXNotifier;
26+
import ro.lmn.maven.dmn.impl.MacOSXOsaNotifier;
2627
import ro.lmn.maven.dmn.impl.SystemTrayNotifier;
2728
import ro.lmn.maven.dmn.impl.WindowsNotifier;
2829

@@ -32,6 +33,7 @@ public class NotifierFactory {
3233
{
3334
notifiers.add(new LinuxNotifier());
3435
notifiers.add(new MacOSXNotifier());
36+
notifiers.add(new MacOSXOsaNotifier());
3537
notifiers.add(new WindowsNotifier());
3638
notifiers.add(new SystemTrayNotifier());
3739

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2017 Denis N. Antonioli
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package ro.lmn.maven.dmn.impl;
17+
18+
import org.apache.maven.artifact.versioning.ComparableVersion;
19+
import ro.lmn.maven.dmn.api.NotificationType;
20+
21+
import java.io.IOException;
22+
23+
/**
24+
* NotifierFactory for Mac OS X based on OSA <code><a href="https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW224>display notification</a></code>.
25+
* Support has been introduced with <code><a href="https://developer.apple.com/library/content/releasenotes/AppleScript/RN-AppleScript/RN-10_9/RN-10_9.html">Mac OS X 10.9</a></code>.
26+
*/
27+
public class MacOSXOsaNotifier extends AbstractNotifier {
28+
29+
public static final String OSASCRIPT = "/usr/bin/osascript";
30+
31+
@Override
32+
public void notify(String title, String details, NotificationType notificationType) throws IOException {
33+
ProcessBuilder builder = new ProcessBuilder(OSASCRIPT, "-e", "display notification \"" + details + "\" with title \"" + title + "\"");
34+
executeProcess(builder);
35+
}
36+
37+
@Override
38+
public boolean isAvailable() {
39+
return OSType.MAC == OSType.getDetected() && osaScriptHasDisplayNotification();
40+
}
41+
42+
private static boolean osaScriptHasDisplayNotification() {
43+
return new ComparableVersion(System.getProperty("os.version")).compareTo(new ComparableVersion("10.9")) >= 0;
44+
}
45+
}

0 commit comments

Comments
 (0)