-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
750 additions
and
3 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
*.o | ||
*.a | ||
*.so | ||
/transmit | ||
|
||
# Folders | ||
_obj | ||
|
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,50 @@ | ||
// | ||
// Copyright (c) 2016 Dean Jackson <deanishe@deanishe.net> | ||
// | ||
// MIT Licence. See http://opensource.org/licenses/MIT | ||
// | ||
// Created on 2016-11-06 | ||
// | ||
|
||
ObjC.import('stdlib') | ||
|
||
var Transmit = Application('Transmit') | ||
Transmit.includeStandardAdditions = true | ||
|
||
// Return favourite for UID or null | ||
function findFave(uid) { | ||
var faves = Transmit.favorites.whose({ | ||
identifier: uid | ||
}) | ||
if (faves.length == 0) { | ||
return null | ||
} | ||
return faves[0] | ||
} | ||
|
||
// Open favourite with UID | ||
function openFave(uid) { | ||
var doc = null, | ||
fav = findFave(uid) | ||
|
||
if (fav === null) { | ||
console.log('Favourite not found: ' + uid) | ||
return false | ||
} | ||
|
||
doc = Transmit.Document().make() | ||
// Activate transmit if necessary | ||
if (!Transmit.frontmost()) { | ||
Transmit.activate() | ||
} | ||
// Open fave | ||
doc.currentTab.connect({to:fav}) | ||
return true | ||
} | ||
|
||
function run(argv) { | ||
var uid = argv[0] | ||
if (!openFave(uid)) { | ||
$.exit(1) | ||
} | ||
} |
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,2 +1,38 @@ | ||
# alfred-transmit | ||
Rapidly search Transmit favourites in Alfred | ||
Alfred Transmit | ||
=============== | ||
|
||
Rapidly search Transmit favourites in [Alfred][alfredapp]. | ||
|
||
|
||
Usage | ||
----- | ||
|
||
- `ftp [<query>]` — View/filter favourites. | ||
- `↩` — Open favourite in Transmit. | ||
|
||
|
||
Configuration | ||
------------- | ||
|
||
The workflow is pre-configured to use the `Favorites.xml` saved by the non-Mac App Store version of Transmit at `~/Library/Application Support/Transmit/Favorites/Favorites.xml`. | ||
|
||
If you bought Transmit from the Mac App Store, you'll need to change the `FAVES_PATH` variable in the workflow configuration sheet to point to your `Favorites.xml` file. | ||
|
||
|
||
Licencing & thanks | ||
------------------ | ||
|
||
- [Transmit][transmit] goes without saying. | ||
- The update icon is from the [Material Design Iconic Font][material] ([SIL licence and others][material-licence]) by [Sergey Kupletsky][sergey]. | ||
- The [AwGo library][awgo] ([MIT Licence][mit]) takes care of the workflowy stuff. | ||
|
||
|
||
[alfredapp]: https://www.alfredapp.com/ | ||
[awgo]: https://godoc.org/gogs.deanishe.net/deanishe/awgo | ||
[mit]: https://raw.githubusercontent.com/deanishe/alfred-ssh/master/LICENCE.txt | ||
[octicons]: https://octicons.github.com/ | ||
[sil]: http://scripts.sil.org/OFL | ||
[material]: https://zavoloklom.github.io/material-design-iconic-font/ | ||
[material-licence]: https://zavoloklom.github.io/material-design-iconic-font/license.html | ||
[sergey]: http://twitter.com/zavoloklom | ||
[transmit]: https://panic.com/transmit/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env zsh | ||
|
||
# programs & scripts | ||
wffiles=(transmit OpenFavourite.js) | ||
# icons | ||
wffiles+=(icon.png update.png) | ||
# data files | ||
wffiles+=(info.plist README.md LICENCE.txt) | ||
|
||
here="$( cd "$( dirname "$0" )"; pwd )" | ||
|
||
log() { | ||
echo "$@" > /dev/stderr | ||
} | ||
|
||
cleanup() { | ||
local p="${here}/build" | ||
log "Cleaning up ..." | ||
test -d "$p" && rm -rf ./build/ | ||
} | ||
|
||
pushd "$here" &> /dev/null | ||
|
||
log "Building executable(s) ..." | ||
go build -v -o ./transmit ./cmd/ | ||
ST_BUILD=$? | ||
if [ "$ST_BUILD" != 0 ]; then | ||
log "Error building executable." | ||
cleanup | ||
popd &> /dev/null | ||
exit $ST_BUILD | ||
fi | ||
|
||
chmod 755 ./transmit | ||
|
||
log | ||
|
||
log "Cleaning ./build ..." | ||
rm -rvf ./build | ||
|
||
log | ||
|
||
log "Copying assets to ./build ..." | ||
|
||
mkdir -vp ./build | ||
|
||
for n in $wffiles; do | ||
cp -v "$n" ./build/ | ||
done | ||
|
||
log | ||
|
||
# Get the dist filename from the executable | ||
zipfile="$(./transmit --distname 2> /dev/null)" | ||
if [ "$?" -ne 0 ]; then | ||
log "Error getting distname from transmit." | ||
cleanup | ||
exit 1 | ||
fi | ||
|
||
log | ||
|
||
if test -e "$zipfile"; then | ||
log "Removing existing .alfredworkflow file ..." | ||
rm -rvf "$zipfile" | ||
log | ||
fi | ||
|
||
pushd ./build/ &> /dev/null | ||
|
||
log "Building .alfredworkflow file ..." | ||
zip -r8n .png "../${zipfile}" ./* | ||
ST_ZIP=$? | ||
if [ "$ST_ZIP" != 0 ]; then | ||
log "Error creating .alfredworkflow file." | ||
popd &> /dev/null | ||
cleanup | ||
popd &> /dev/null | ||
exit $ST_ZIP | ||
fi | ||
popd &> /dev/null | ||
|
||
log | ||
|
||
cleanup | ||
|
||
log "Wrote '${zipfile}' in '$( pwd )'" | ||
|
||
popd &> /dev/null |
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,160 @@ | ||
// | ||
// Copyright (c) 2016 Dean Jackson <deanishe@deanishe.net> | ||
// | ||
// MIT Licence. See http://opensource.org/licenses/MIT | ||
// | ||
// Created on 2016-11-06 | ||
// | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"os" | ||
|
||
"strings" | ||
|
||
"github.com/deanishe/alfred-transmit" | ||
"github.com/docopt/docopt-go" | ||
"gogs.deanishe.net/deanishe/awgo" | ||
) | ||
|
||
var usage = `transmit [options] [<query>] | ||
Search and open Transmit favourites. | ||
Usage: | ||
transmit [<query>] | ||
transmit -u | ||
transmit --distname | ||
Options: | ||
-u, --update Check for workflow update. | ||
--distname Print name of workflow file (for building). | ||
-h, --help Show this help message. | ||
--version Show version. | ||
` | ||
|
||
var ( | ||
iconUpdate = &aw.Icon{Value: "update.png"} | ||
favesPath string | ||
// Command-line flags | ||
doUpdate bool | ||
doDist bool | ||
query string | ||
// Workflow configuration | ||
opts *aw.Options | ||
wf *aw.Workflow | ||
) | ||
|
||
func init() { | ||
// Command-line flags | ||
opts = &aw.Options{ | ||
GitHub: "deanishe/alfred-transmit", | ||
} | ||
wf = aw.NewWorkflow(opts) | ||
} | ||
|
||
func parseArgs() { | ||
args, _ := docopt.Parse(usage, wf.Args(), true, wf.Version(), false) | ||
// log.Printf("args=%#v", args) | ||
if args["--update"] != false { | ||
doUpdate = true | ||
} | ||
if args["--distname"] != false { | ||
doDist = true | ||
} | ||
if args["<query>"] != nil { | ||
query = args["<query>"].(string) | ||
} | ||
} | ||
|
||
// Check for updates | ||
func runUpdate() { | ||
wf.TextErrors = true | ||
log.Println("Checking for update...") | ||
if err := wf.CheckForUpdate(); err != nil { | ||
wf.FatalError(err) | ||
} | ||
} | ||
|
||
// Print workflow file name | ||
func runDist() { | ||
name := strings.Replace( | ||
fmt.Sprintf("%s-%s.alfredworkflow", wf.Name(), wf.Version()), | ||
" ", "-", -1) | ||
fmt.Print(name) | ||
} | ||
|
||
func run() { | ||
parseArgs() | ||
|
||
// ---------------------------------------------------------------- | ||
// Check for updates if --update was passed | ||
if doUpdate { | ||
runUpdate() | ||
return | ||
} | ||
|
||
// ---------------------------------------------------------------- | ||
// Print distname if --distname was passed | ||
if doDist { | ||
runDist() | ||
return | ||
} | ||
|
||
// ---------------------------------------------------------------- | ||
// Updates | ||
if wf.UpdateCheckDue() { | ||
wf.Var("check_update", "1") | ||
} | ||
// Inform of update if query is empty | ||
if wf.UpdateAvailable() && query == "" { | ||
wf.NewItem("An update is available"). | ||
Subtitle("↩ or ⇥ to install update"). | ||
Valid(false). | ||
Autocomplete("workflow:update"). | ||
Icon(iconUpdate) | ||
} | ||
|
||
// ---------------------------------------------------------------- | ||
// Load data | ||
favesPath = strings.Replace(os.Getenv("FAVES_PATH"), "~", os.Getenv("HOME"), 1) | ||
transmit.BookmarksPath = favesPath | ||
log.Printf("Favorites.xml: %s", favesPath) | ||
log.Printf("query=%s", query) | ||
|
||
faves, err := transmit.Favourites() | ||
if err != nil { | ||
log.Printf("Error fetching favourites: %s", err) | ||
wf.FatalError(err) | ||
} | ||
log.Printf("%d favourites.", len(faves)) | ||
|
||
// ---------------------------------------------------------------- | ||
// Display results | ||
for _, fav := range faves { | ||
wf.NewItem(fav.Name). | ||
Subtitle(fav.Server). | ||
Arg(fav.ID). | ||
UID(fav.ID). | ||
Valid(true). | ||
SortKey(fmt.Sprintf("%s %s", fav.Name, fav.Server)) | ||
} | ||
|
||
if query != "" { | ||
res := wf.Filter(query) | ||
for i, r := range res { | ||
log.Printf("%02d. %4.2f %s", i+1, r.Score, r.SortKey) | ||
} | ||
} | ||
|
||
wf.WarnEmpty("No favourites found", "Try a different query?") | ||
wf.SendFeedback() | ||
} | ||
|
||
func main() { | ||
wf.Run(run) | ||
} |
Oops, something went wrong.