This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from goropikari/dev
Increase functions for macOS.
- Loading branch information
Showing
12 changed files
with
217 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
# Notifier | ||
[![Notifier](http://pkg.julialang.org/badges/Notifier_0.6.svg)](http://pkg.julialang.org/detail/Notifier) | ||
[![Build Status](https://travis-ci.org/goropikari/Notifier.jl.svg?branch=master)](https://travis-ci.org/goropikari/Notifier.jl) | ||
[![codecov.io](http://codecov.io/github/goropikari/Notifier.jl/coverage.svg?branch=master)](http://codecov.io/github/goropikari/Notifier.jl?branch=master) | ||
|
||
This package is notification tools for Julialang. | ||
|
||
## Features: | ||
- Linux | ||
- desktop notification | ||
- sound notification | ||
- email notification | ||
- macOS | ||
- desktop notification | ||
- sound notification | ||
- email notification | ||
- say notification (Read given massage aloud) | ||
- Windows (Experimental) | ||
- desktop notification | ||
- sound notification | ||
|
||
## Installation | ||
```Julia | ||
Pkg.add("Notifier") | ||
# Pkg.checkout("Notifier") # checkout master branch | ||
``` | ||
|
||
# Linux OS | ||
|
@@ -20,7 +36,7 @@ Before using Notifier.jl, you need to install following softwares in your Linux | |
$ sudo apt install libnotify-bin alsa-utils mailutils heirloom-mailx bsd-mailx | ||
``` | ||
|
||
This package uses `mail` linux command to notify by e-mail. Thus you need some settings in advance. | ||
This package uses `mail` command to notify by e-mail. Thus you need some settings in advance. | ||
If following command works correctly, you don't need further setting. | ||
```bash | ||
$ echo test | mail -s foo [email protected] | ||
|
@@ -30,15 +46,15 @@ $ echo test | mail -s foo [email protected] | |
### popup notification | ||
```Julia | ||
using Notifier | ||
notify("calculation done") | ||
notify("Task completed") | ||
# defalut title is "Julia". | ||
# You can change the title by title option. | ||
notify("calculation done", title="foofoo") | ||
notify("calculation done", sound=true) # with sound | ||
notify("calculation done", sound="./foo.wav") # specify a sound file | ||
alarm() # only sound. You can specify a sound file, alarm(sound="./foo.wav") | ||
notify("Task completed", title="foofoo") | ||
notify("Task completed", sound=true) # with sound | ||
notify("Task completed", sound="foo.wav") # specify a sound file | ||
alarm() # only sound. You can specify a sound file, alarm(sound="foo.wav") | ||
``` | ||
![Screenshot of a Notification](./docs/popup.png?raw=true) | ||
![Screenshot of a Notification](./docs/linuxpopup.png?raw=true) | ||
|
||
### e-mail notification | ||
```Julia | ||
|
@@ -65,14 +81,17 @@ email("message") | |
|
||
# macOS | ||
## Usage | ||
|
||
### popup notification | ||
```julia | ||
using Notifier | ||
notify("Task completed") | ||
notify("Notification with sound", sound=true) # you can also specify a sound file | ||
notify("Change title", title="foofoo") | ||
notify("Notification with sound", sound=true) | ||
alarm() # only sound. You can specify a sound file, alarm(sound="foo.wav") | ||
say("Finish calculation!") # Read aloud | ||
``` | ||
|
||
![Screenshot of a Notification](./docs/screenshot.png?raw=true) | ||
![Screenshot of a Notification](./docs/macpopup.png?raw=true) | ||
|
||
Other supported parameters include `group` and `subtitle`. | ||
|
||
|
@@ -91,6 +110,28 @@ notify("Notification B", group="group2") | |
Notifier.remove("group1") | ||
``` | ||
|
||
### e-mail notification | ||
```Julia | ||
email("message", To="[email protected]") # default subject is set by date. | ||
email("message", subject="result", To="[email protected]") | ||
``` | ||
|
||
|
||
If you use "email" function frequently, I recommend you to register your email address by "register_email" function. | ||
```Julia | ||
julia> register_email() | ||
Type your desired recipient e-mail address to receive a notification. | ||
e-mail: foo@example.com | ||
|
||
Recipient e-mail address is saved at /path/to/.julia/v0.6/Notifier/email/address.txt. | ||
If you want to change the address, modify /path/to/.julia/v0.6/Notifier/email/address.txt directly or run register_email() again | ||
``` | ||
|
||
After you registered, you don't need to specify e-mail address. | ||
```Julia | ||
email("message") | ||
``` | ||
|
||
# Windows (Experimental) | ||
## Usage | ||
```Julia | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
export register_email, email | ||
|
||
""" | ||
Notifier.register_email() | ||
Register a recipient e-mail address. | ||
""" | ||
function register_email() | ||
emaildir = joinpath(@__DIR__, "..", "email") | ||
mkpath(emaildir) | ||
|
||
if ispath(joinpath(emaildir, "address.txt")) | ||
println("An e-mail address is already registered.") | ||
print("Do you overwrite? [y/n]: ") | ||
YesNo = lowercase(chomp(readline(STDIN))) | ||
|
||
if YesNo ∈ ["n", "no"] | ||
return nothing | ||
end | ||
end | ||
|
||
println("\nType your desired recipient e-mail address to receive a notification.") | ||
print("e-mail: ") | ||
To = chomp(readline(STDIN)) | ||
fp = open(joinpath(emaildir, "address.txt"), "w") | ||
write(fp, To) | ||
close(fp) | ||
|
||
println("\nRecipient e-mail address is saved at $(abspath((joinpath(emaildir, "address.txt")))).") | ||
println("If you want to change the address, modify $(abspath((joinpath(emaildir, "address.txt")))) directly or run register_email() again.") | ||
end | ||
|
||
""" | ||
Notifier.email(message; subject, To) | ||
Send email to specific email address. | ||
# Arguments | ||
- `To::AbstractString`: recipient email adress. | ||
""" | ||
function email(message; subject="$(round(now(), Dates.Second(1)))", To="") | ||
emaildir = joinpath(@__DIR__, "..", "email") | ||
if isempty(To) | ||
if ispath(joinpath(emaildir, "address.txt")) | ||
To = readline(joinpath(emaildir, "address.txt")) | ||
else | ||
error("""Email address is not specified. | ||
In order to send an e-mail, you should register an e-mail address by | ||
register_email() | ||
or specify the address by using To option. | ||
email(\"some messages\", To=\"[email protected]\").""") | ||
end | ||
end | ||
run(pipeline(`echo $message`, `mail -s $subject $To`)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import Base.notify | ||
export notify, alarm, register_email, email | ||
|
||
@doc """ | ||
include("email.jl") | ||
|
||
""" | ||
--- | ||
Notifier.notify(message::AbstractString; title::AbstractString, sound, time) | ||
Notifier.notify(message; title="Julia", sound=false, time=4) | ||
Notify by desktop notification. | ||
defalut parameter\n | ||
title = "Julia"\n | ||
sound = false\n | ||
time = 4 # display time (seconds) | ||
""" notify | ||
# Arguments | ||
- `sound::Union{Bool, AbstractString}`: Play default sound or specific sound. | ||
- `time::Real`: display time. | ||
""" | ||
function notify(message::AbstractString; | ||
title="Julia", | ||
sound::Union{Bool, AbstractString}=false, | ||
|
@@ -26,67 +29,13 @@ function notify(message::AbstractString; | |
return | ||
end | ||
|
||
@doc """ | ||
Notifier.alarm(;sound::AbstractString) | ||
notify by sound | ||
""" | ||
Notifier.alarm(;sound="defalut.wav") | ||
if you choose a specific sound WAV file, you can use it instead of the defalut sound. | ||
""" alarm | ||
Notify by sound. | ||
If you choose a specific sound WAV file, you can play it instead of the defalut sound. | ||
""" | ||
function alarm(;sound::AbstractString=joinpath(@__DIR__, "default.wav")) | ||
@async run(`aplay -q $sound`) | ||
return nothing | ||
end | ||
|
||
@doc """ | ||
Notifier.register_email() | ||
register a recipient e-mail address | ||
""" register_email | ||
function register_email() | ||
emaildir = joinpath(@__DIR__, "..", "email") | ||
mkpath(emaildir) | ||
|
||
if ispath(joinpath(emaildir, "address.txt")) | ||
println("An e-mail address is already registered.") | ||
println("Do you overwrite? [y/n]") | ||
YesNo = lowercase(chomp(readline(STDIN))) | ||
|
||
if YesNo ∈ ["n", "no"] | ||
return | ||
end | ||
end | ||
|
||
println("\nType your desired recipient e-mail address to receive a notification.") | ||
print("e-mail: ") | ||
To = chomp(readline(STDIN)) | ||
fp = open(joinpath(emaildir, "address.txt"), "w") | ||
write(fp, To) | ||
close(fp) | ||
|
||
println("\nRecipient e-mail address is saved at $(abspath((joinpath(emaildir, "address.txt")))).") | ||
println("If you want to change the address, modify $(abspath((joinpath(emaildir, "address.txt")))) directly or run register_email() again.") | ||
end | ||
|
||
@doc """ | ||
Notifier.email(message; subject, To) | ||
defalut\n | ||
subject="\$(round(now(), Dates.Second(1)))"\n | ||
To="not-specified"\n | ||
function email(message; subject="$(round(now(), Dates.Second(1)))", To="not-specified") | ||
emaildir = joinpath(@__DIR__, "..", "email") | ||
if To == "not-specified" | ||
if ispath(joinpath(emaildir, "address.txt")) | ||
To = readline(joinpath(emaildir, "address.txt")) | ||
else | ||
println("Email address is not specified.") | ||
println("In order to send an e-mail, register an e-mail address by register_email() or") | ||
println("specify it by To option like") | ||
println(" email(\"some messages\", To=\"[email protected]\").") | ||
|
||
return | ||
end | ||
end | ||
run(pipeline(`echo $message`, `mail -s $subject $To`)) | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.