Skip to content

feat(LuaExtension): Extension for VOX #1076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions extensions/vox/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Released under MIT license.

Copyright (c) 2014 Linell Bonnette

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
312 changes: 312 additions & 0 deletions extensions/vox/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
--- === hs.vox ===
---
--- Controls for VOX music player

local vox = {}

local alert = require "hs.alert"
local as = require "hs.applescript"
local app = require "hs.application"

-- Internal function to pass a command to Applescript.
local function tell(cmd)
local _cmd = 'tell application "vox" to ' .. cmd
local ok, result = as.applescript(_cmd)
if ok then
return result
else
return nil
end
end

--- hs.vox.pause()
--- Function
--- Pauses the current vox track
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.pause()
tell('pause')
end

--- hs.vox.play()
--- Function
--- Plays the current vox track
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.play()
tell('play')
end

--- hs.vox.playpause()
--- Function
--- Toggles play/pause of current vox track
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.playpause()
tell('playpause')
end

--- hs.vox.next()
--- Function
--- Skips to the next track
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.next()
tell('next track')
end

--- hs.vox.previous()
--- Function
--- Skips to previous track
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.previous()
tell('previous track')
end

--- hs.vox.shuffle()
--- Function
--- Toggle shuffle state of current list
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.shuffle()
tell('shuffle')
end

--- hs.vox.playurl(url)
--- Function
--- Play media from the given URL
---
--- Parameters:
--- * url {string}
---
--- Returns:
--- * None
function vox.playurl(url)
tell('playurl \"' .. url .. '\"')
end

--- hs.vox.addurl(url)
--- Function
--- Add media URL to current list
---
--- Parameters:
--- * url {string}
---
--- Returns:
--- * None
function vox.addurl(url)
tell('addurl \"' .. url .. '\"')
end

--- hs.vox.forward()
--- Function
--- Skips the playback position forwards by about 7 seconds
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.forward()
tell('rewindforward')
end

--- hs.vox.backward()
--- Function
--- Skips the playback position backwards by about 7 seconds
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.backward()
tell('rewindbackward')
end

--- hs.vox.fastForward()
--- Function
--- Skips the playback position forwards by about 17 seconds
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.fastForward()
tell('rewindforwardfast')
end

--- hs.vox.fastBackward()
--- Function
--- Skips the playback position backwards by about 14 seconds
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.fastBackward()
tell('rewindbackwardfast')
end

--- hs.vox.increaseVolume()
--- Function
--- Increases the palyer volume
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.increaseVolume()
tell('increasvolume')
end

--- hs.vox.decreaseVolume()
--- Function
--- Decreases the player volume
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.decreaseVolume()
tell('decreasevolume')
end

--- hs.vox.togglePlaylist()
--- Function
--- Toggle playlist
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.togglePlaylist()
tell('showhideplaylist')
end

--- hs.vox.trackInfo()
--- Function
--- Displays information for current track on screen
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
function vox.trackInfo()
local artist = tell('artist') or "Unknown artist"
local album = tell('album') or "Unknown album"
local track = tell('track') or "Unknown track"
alert.show(track .."\n".. album .."\n".. artist, 1.75)
end

--- hs.vox.getCurrentArtist()
--- Function
--- Gets the name of the artist of the current track
---
--- Parameters:
--- * None
---
--- Returns:
--- * A string containing the Artist of the current track, or nil if an error occurred
function vox.getCurrentArtist()
return tell('artist') or "Unknown artist"
end

--- hs.vox.getCurrentAlbum()
--- Function
--- Gets the name of the album of the current track
---
--- Parameters:
--- * None
---
--- Returns:
--- * A string containing the Album of the current track, or nil if an error occurred
function vox.getCurrentAlbum()
return tell('album') or "Unknown album"
end

--- hs.vox.getAlbumArtist()
--- Function
--- Gets the artist of current Album
---
--- Parameters:
--- * None
---
--- Returns:
--- * A string containing the artist of current Album, or nil if an error occurred
function vox.getAlbumArtist()
return tell('albumArtist') or "Unknown album artist"
end

--- hs.vox.getUniqueID()
--- Function
--- Gets the uniqueID of the current track
---
--- Parameters:
--- * None
---
--- Returns:
--- * A string containing the name of the current track, or nil if an error occurred
function vox.getUniqueID()
return tell('uniqueID') or "Unknown ID"
end

--- hs.vox.getPlayerState()
--- Function
--- Gets the current playback state of vox
---
--- Parameters:
--- * None
---
--- Returns:
--- * 0 for paused
--- * 1 for playing
function vox.getPlayerState()
return tell('playerState')
end

--- hs.vox.isRunning()
--- Function
--- Returns whether VOX is currently open
---
--- Parameters:
--- * None
---
--- Returns:
--- * A boolean value indicating whether the vox application is running
function vox.isRunning()
return app.get("VOX"):isRunning() ~= nil
end

return vox
1 change: 1 addition & 0 deletions scripts/copy_extensions_to_bundle.sh
Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ export HS_LUAONLY="_coresetup \
spaces \
tabs \
utf8 \
vox \
doc"

# First, copy all of our init.lua's into the destination bundle