boB Rudis
4 years ago
21 changed files with 394 additions and 10 deletions
@ -0,0 +1,65 @@ |
|||
create_new_bitbar_script <- function() { |
|||
|
|||
miniPage( |
|||
gadgetTitleBar("New BitBar"), |
|||
miniContentPanel( |
|||
shiny::textInput( |
|||
inputId = "save_as", label = "Save as:", width="100%", |
|||
value = file.path(bitbar_plugins_dir(), sprintf("%s-new-plugin.R", ulid::generate())), |
|||
), |
|||
shiny::textInput( |
|||
inputId = "title", label = "Title:", value = "Script Title", width="100%", |
|||
), |
|||
shiny::textInput( |
|||
inputId = "version", label = "Version:", value = "1.0", width="100%", |
|||
), |
|||
shiny::textInput( |
|||
inputId = "author", label = "Author:", value = Sys.info()[["user"]], width="100%", |
|||
), |
|||
shiny::textInput( |
|||
inputId = "github_user", label = "GitHub User:", value = Sys.info()[["user"]], width="100%", |
|||
), |
|||
shiny::textInput( |
|||
inputId = "description", label = "Description:", value = "BitBar Plugin Using R", width="100%", |
|||
), |
|||
shiny::textInput( |
|||
inputId = "dependencies", label = "Dependencies:", value = "R", width="100%", |
|||
), |
|||
shiny::textInput( |
|||
inputId = "image_url", label = "Image URL:", value = "", width="100%", |
|||
), |
|||
shiny::textInput( |
|||
inputId = "about_url", label = "About URL:", value = "", width="100%", |
|||
) |
|||
) |
|||
) -> ui |
|||
|
|||
server <- function(input, output, session) { |
|||
|
|||
observeEvent(input$done, { |
|||
|
|||
bitbar::new_bitbar_script( |
|||
save_as = input$save_as, |
|||
title = input$title, |
|||
version = input$version, |
|||
author = input$author, |
|||
github_user = input$github_user, |
|||
description = input$description, |
|||
dependencies = input$dependencies, |
|||
image_url = input$image_url, |
|||
about_url = input$about_url |
|||
) |
|||
|
|||
stopApp(returnValue) |
|||
|
|||
}) |
|||
|
|||
} |
|||
|
|||
viewer <- dialogViewer("New BitBar", width = 400, height = 800) |
|||
|
|||
runGadget(ui, server, viewer = viewer) |
|||
|
|||
} |
|||
|
|||
|
@ -0,0 +1,37 @@ |
|||
#' Return a base64 encoded string of an image (local filesystem or URL) |
|||
#' |
|||
#' @param path_or_url local path or URL for the image |
|||
#' @export |
|||
b64_image <- function(path_or_url) { |
|||
|
|||
path_or_url <- path_or_url[1] |
|||
if (grepl("^http[s]*://", path_or_url)) { |
|||
|
|||
httr::GET( |
|||
url = path_or_url, |
|||
httr::write_memory() |
|||
) -> res |
|||
|
|||
httr::stop_for_status(res) |
|||
|
|||
bytes <- httr::content(res, as = "raw", encoding = "UTF-8") |
|||
|
|||
} else { |
|||
|
|||
path_or_url <- path.expand(path_or_url) |
|||
file_size <- file.info(path_or_url)$size |
|||
|
|||
stopifnot( |
|||
c( |
|||
"File not found." = file.exists(path_or_url), |
|||
"File is empty." = file.info(path_or_url)$size > 0 |
|||
) |
|||
) |
|||
|
|||
bytes <- readBin(path_or_url, "raw", n = file.info(path_or_url)$size) |
|||
|
|||
} |
|||
|
|||
openssl::base64_encode(bytes) |
|||
|
|||
} |
@ -0,0 +1,6 @@ |
|||
#' Images that come with the package |
|||
#' |
|||
#' @export |
|||
r_logo_small <- function() { |
|||
system.file("img", "r-logo-small.png", package="bitbar") |
|||
} |
@ -0,0 +1,42 @@ |
|||
read_bitbar_prefs <- function() { |
|||
|
|||
bbprefs <- path.expand("~/Library/Preferences/com.matryer.BitBar.plist") |
|||
|
|||
if (!file.exists(bbprefs)) { |
|||
|
|||
stop( |
|||
paste0(strwrap(paste0(c( |
|||
"BitBar preferences file not found. ", |
|||
"This likely means BitBar is not installed. ", |
|||
"Please install BitBar before using the {bitbar} package." |
|||
), collapse = "")), collapse="\n"), |
|||
call.=FALSE |
|||
) |
|||
} |
|||
|
|||
tf <- tempfile(fileext = ".xml") |
|||
on.exit(unlink(tf)) |
|||
|
|||
sys::exec_internal( |
|||
cmd = "plistutil", |
|||
args = c("--infile", bbprefs, "--outfile", tf) |
|||
) -> res |
|||
|
|||
if (res$status == 0) { |
|||
|
|||
res <- XML::readKeyValueDB(tf) |
|||
res |
|||
|
|||
} else { |
|||
stop("Error reading BitBar preferences.", call.=FALSE) |
|||
} |
|||
|
|||
} |
|||
|
|||
#' BitBar plugins directory |
|||
#' |
|||
#' @export |
|||
bitbar_plugins_dir <- function() { |
|||
prefs <- read_bitbar_prefs() |
|||
prefs[["pluginsDirectory"]] |
|||
} |
@ -0,0 +1,99 @@ |
|||
|
|||
[![Project Status: Active – The project has reached a stable, usable |
|||
state and is being actively |
|||
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) |
|||
[![Signed |
|||
by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr) |
|||
![Signed commit |
|||
%](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg) |
|||
[![Linux build |
|||
Status](https://travis-ci.org/hrbrmstr/bitbar.svg?branch=master)](https://travis-ci.org/hrbrmstr/bitbar) |
|||
![Minimal R |
|||
Version](https://img.shields.io/badge/R%3E%3D-3.5.0-blue.svg) |
|||
![License](https://img.shields.io/badge/License-MIT-blue.svg) |
|||
|
|||
# bitbar |
|||
|
|||
Craft macOS Menu Bar Applications with Rscript |
|||
|
|||
## Description |
|||
|
|||
Mat Ryer’s macOS utility <https://getbitbar.com/> enables any script to |
|||
become a menu bar application. Tools are provided to make it easier to |
|||
craft these scripts. |
|||
|
|||
## Installing BitBar |
|||
|
|||
If you have [homebrew](https://brew.sh/) installed, you can do: |
|||
|
|||
``` shell |
|||
brew cask install bitbar |
|||
``` |
|||
|
|||
Otherwise [grab the latest |
|||
release](https://github.com/matryer/bitbar/releases/latest) and install |
|||
it the hard way. |
|||
|
|||
Open the application and choose the directory you want to be your |
|||
plugins directory. This is where your menubar scripts will go. (I use |
|||
`~/Library/Application Support/BitBar/Plugins` but you can pick any |
|||
directory; just make sure it isn’t one with a gazillion files as that |
|||
impacts BitBar’s performance). |
|||
|
|||
## What’s Inside The Tin |
|||
|
|||
The following functions are implemented: |
|||
|
|||
- `add_entry`: Add an entry to the menu |
|||
- `bitbar_plugins_dir`: BitBar plugins directory |
|||
- `new_bitbar_script`: Helper to get started with a new BitBar bitbar |
|||
script |
|||
|
|||
## Installation |
|||
|
|||
``` r |
|||
remotes::install_git("https://git.rud.is/hrbrmstr/bitbar.git") |
|||
# or |
|||
remotes::install_git("https://git.sr.ht/~hrbrmstr/bitbar") |
|||
# or |
|||
remotes::install_gitlab("hrbrmstr/bitbar") |
|||
# or |
|||
remotes::install_bitbucket("hrbrmstr/bitbar") |
|||
``` |
|||
|
|||
NOTE: To use the ‘remotes’ install options you will need to have the |
|||
[{remotes} package](https://github.com/r-lib/remotes) installed. |
|||
|
|||
## Usage |
|||
|
|||
``` r |
|||
library(bitbar) |
|||
|
|||
# current version |
|||
packageVersion("bitbar") |
|||
## [1] '0.1.0' |
|||
``` |
|||
|
|||
This will open up a `my-awesome-bitbar-script.R` in RStudio (if |
|||
available) or whatever editor `file.edit()` is configured to use. |
|||
|
|||
``` r |
|||
new_bitbar_script( |
|||
save_as = file.path(bitbar_plugins_dir(), "my-awesome-bitbar-script.R"), |
|||
title = ":blue_heart:", |
|||
description = "Example BitBar Script") |
|||
) |
|||
``` |
|||
|
|||
## bitbar Metrics |
|||
|
|||
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | |
|||
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: | |
|||
| R | 7 | 0.88 | 96 | 0.88 | 29 | 0.57 | 68 | 0.63 | |
|||
| Rmd | 1 | 0.12 | 13 | 0.12 | 22 | 0.43 | 40 | 0.37 | |
|||
|
|||
## Code of Conduct |
|||
|
|||
Please note that this project is released with a Contributor Code of |
|||
Conduct. By participating in this project you agree to abide by its |
|||
terms. |
After Width: | Height: | Size: 674 B |
Binary file not shown.
@ -0,0 +1,4 @@ |
|||
Name: Create a new {bitbar} script |
|||
Description: Create a new {bitbar} script |
|||
Binding: create_new_bitbar_script |
|||
Interactive: true |
@ -0,0 +1,14 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/base64-image.R |
|||
\name{b64_image} |
|||
\alias{b64_image} |
|||
\title{Return a base64 encoded string of an image (local filesystem or URL)} |
|||
\usage{ |
|||
b64_image(path_or_url) |
|||
} |
|||
\arguments{ |
|||
\item{path_or_url}{local path or URL for the image} |
|||
} |
|||
\description{ |
|||
Return a base64 encoded string of an image (local filesystem or URL) |
|||
} |
@ -0,0 +1,11 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/read-bitbar-prefs.R |
|||
\name{bitbar_plugins_dir} |
|||
\alias{bitbar_plugins_dir} |
|||
\title{BitBar plugins directory} |
|||
\usage{ |
|||
bitbar_plugins_dir() |
|||
} |
|||
\description{ |
|||
BitBar plugins directory |
|||
} |
@ -0,0 +1,11 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/imgs.R |
|||
\name{r_logo_small} |
|||
\alias{r_logo_small} |
|||
\title{Images that come with the package} |
|||
\usage{ |
|||
r_logo_small() |
|||
} |
|||
\description{ |
|||
Images that come with the package |
|||
} |
Loading…
Reference in new issue