Giter Site home page Giter Site logo

coolaj86 / osx-wifi-volume-remote Goto Github PK

View Code? Open in Web Editor NEW
31.0 8.0 6.0 68 KB

A web-based html5 / node.js app to control OS X system volume from iPhone, Android, etc

License: Apache License 2.0

JavaScript 75.60% AppleScript 0.89% HTML 13.86% Pug 9.65%

osx-wifi-volume-remote's Introduction

OS X WiFi Volume Remote

A web-based html5 / node.js app to control OS X system volume from iPhone, Android, etc

screenshot

Installation & Usage

  1. Get Node.js

  2. Open Terminal

  3. Install osx-wifi-volume-remote like so

    npm install -g osx-wifi-volume-remote
    
  4. Start the server like so (and note that it shows the name of your computer)

    osx-wifi-volume-server 4040
    
  5. Type the http://<your-computer-name>.local:4040/ whatever onto your phone's browser (NOTE: Your phone or whatever device must be on the same WiFi or ethernet network as your computer)

  6. Enjoy controlling your MacBook's volume over wifi!

API Example

npm install osx-wifi-volume-remote

(function () {
  "use strict";

  var applvol = require("osx-wifi-volume-remote");
  // All callbacks have the same arguments
  applvol.get(function (err, volume, muted) {
    console.log(
      "Volume is set to " +
        volume +
        "% and is " +
        (muted ? "" : "not ") +
        "muted"
    );
  });
})();

API

  • get(cb) read the current volume level and mute status
  • fade(cb, level, duration) specify a volume level to fade to
  • fadeBy(cb, difference, duration) specify a positive or negative difference in volume to fade to
  • mute(cb, duration) fades to 0, mutes, then restores volume while muted
  • unmute(cb, duration) sets volume to 0, unmutes, then fades back in to volume level
  • set(cb, level) hard set a volume without fading
  • all callbacks have the arguments err, volume, muted

NOTE: The callbacks all must come first (it was just easier to write the code that way).

Development

If you want to develop, here's the clone and build process:

git clone https://github.com/coolaj86/osx-wifi-volume-remote.git
pushd osx-wifi-volume-remote

npm install -g jade
jade browser/index.jade; mv browser/index.html public/

npm install
node app 4040

AppleScript

I had to learn a bit of AppleScript to get this all together. I'll give the gist of it below an you can also read the article on my blog.

# Check volume level and mute status
osascript -e "output volume of (get volume settings) & output muted of (get volume settings)"

# Mute
osascript -e "set volume with output muted"

# Unmute
osascript -e "set volume without output muted"

# Mute status
osascript -e "output muted of (get volume settings)"

# Set volume by 100ths
osascript -e "set volume output volume 51 --100%"

# Set to 0% without muting (the secret lowest possible setting)
osascript -e "set volume without output muted output volume 0 --100%"

# Set to non-0 without unmuting
osascript -e "set volume with output muted output volume 42 --100%"

# Decrement the current volume by 1
osascript -e "set volume output volume (output volume of (get volume settings) - 1) --100%"

It turns out that AppleScript takes about 80ms to start up and run, so for the fade I actually create a file with the whole loop unrolled and it looks like this:

set volume without output muted output volume 18 --100%
delay 0.033
set volume without output muted output volume 17 --100%
delay 0.033
set volume without output muted output volume 16 --100%

osx-wifi-volume-remote's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

osx-wifi-volume-remote's Issues

double click causes app crash

repro:
launch app
osx-wifi-volume-server 4040

navigate to url
double click on < or > button

actual:
crash
events.js:85
throw er; // Unhandled 'error' event
^
Error: write after end
at ServerResponse.OutgoingMessage.write (_http_outgoing.js:413:15)
at ServerResponse.res.write (/usr/local/lib/node_modules/osx-wifi-volume-remote/node_modules/express/node_modules/connect/lib/middleware/compress.js:110:17)
at ServerResponse.res.end (/usr/local/lib/node_modules/osx-wifi-volume-remote/node_modules/express/node_modules/connect/lib/middleware/compress.js:116:14)
at ServerResponse.res.send (/usr/local/lib/node_modules/osx-wifi-volume-remote/node_modules/express/lib/response.js:152:8)
at ServerResponse.res.json (/usr/local/lib/node_modules/osx-wifi-volume-remote/node_modules/express/lib/response.js:194:15)
at ServerResponse.res.send (/usr/local/lib/node_modules/osx-wifi-volume-remote/node_modules/express/lib/response.js:120:21)
at respond (/usr/local/lib/node_modules/osx-wifi-volume-remote/app.js:57:11)
at null._onTimeout (/usr/local/lib/node_modules/osx-wifi-volume-remote/lib/osascript-vol-ctrl.js:115:9)
at Timer.listOnTimeout (timers.js:110:15)

expected:
no crash

Often off by 1

Something is probably wrong in stepper.js' unroll because changing from 87 to 86 seems impossible.

Likewise, adjusting the slider to 72 results in a volume level of 73.

Question: what does the "--100%" do?

I've seen this a couple places but no explanation.

From what I tested, it looks like

set volume without output muted output volume 18

and

set volume without output muted output volume 18 --100%

seem to do the same thing, but I'm guessing there's a reason people use the --100% but I don't know why.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.