Skip to content

Instantly share code, notes, and snippets.

@danstreeter
Created December 23, 2018 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danstreeter/f6eaefb445347cd77dfa2015bde72f6d to your computer and use it in GitHub Desktop.
Save danstreeter/f6eaefb445347cd77dfa2015bde72f6d to your computer and use it in GitHub Desktop.
Alfred 3 Workflow to list and open VSCode Workspaces.
from os import listdir
from os.path import isfile, join, expanduser
import json
import copy
new_list = list()
new_file_dict = {
"uid": "",
"path": "",
"title": "",
"subtitle": "",
"arg": "",
"match": "",
"icon": {
"path": "./vscode.png"
}
}
myPath = "~/VSCodeWorkspaces/"
realPath = expanduser(myPath)
onlyFiles = [myPath + f for f in listdir(realPath) if isfile(join(realPath, f)) and f.find(".code-workspace") != -1]
arr = {
"items": []
}
for filename in onlyFiles:
new_list = copy.deepcopy(new_file_dict)
name = filename.replace(myPath, "").replace(".code-workspace", "")
new_list['uid'] = filename
new_list['path'] = filename
new_list['title'] = name
new_list['subtitle'] = filename
new_list['arg'] = filename
new_list['match'] = name
arr['items'].append(new_list)
print(json.dumps(arr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment