Skip to content

Instantly share code, notes, and snippets.

@etuttle
Last active July 4, 2020 05:40
Show Gist options
  • Save etuttle/a19528c85a9d29d8c4d7232ad09bb82f to your computer and use it in GitHub Desktop.
Save etuttle/a19528c85a9d29d8c4d7232ad09bb82f to your computer and use it in GitHub Desktop.
Automator service for easy git clonin'
## Paste this to run this script:
## bash -c "$(curl -s https://codeload.github.com/gist/a19528c85a9d29d8c4d7232ad09bb82f/zip/master | bsdtar -Oxvf - '*/_INSTALL.sh')"
set -ex
services="${HOME}/Library/Services"
service="Clone To VSCode.workflow"
repo="https://gist.github.com/a19528c85a9d29d8c4d7232ad09bb82f.git"
mkdir -p "$services"
cd "$services"
if ! test -d "$service"; then
git clone "$repo" "$service"
else
git -C "$service" pull
fi
cd "$service"
# gists don't support dirs, but I'm determined, it's a gist
test -d Contents || mkdir Contents
ln -f Info.plist document.wflow Contents
# open it with Automator to make sure the service is compiled and installed
open -a /Applications/Automator.app "${services}/${service}"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AMApplicationBuild</key>
<string>444.7</string>
<key>AMApplicationVersion</key>
<string>2.8</string>
<key>AMDocumentVersion</key>
<string>2</string>
<key>actions</key>
<array>
<dict>
<key>action</key>
<dict>
<key>AMAccepts</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Optional</key>
<true/>
<key>Types</key>
<array>
<string>com.apple.applescript.object</string>
</array>
</dict>
<key>AMActionVersion</key>
<string>1.0.2</string>
<key>AMApplication</key>
<array>
<string>Automator</string>
</array>
<key>AMParameterProperties</key>
<dict>
<key>source</key>
<dict/>
</dict>
<key>AMProvides</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Types</key>
<array>
<string>com.apple.applescript.object</string>
</array>
</dict>
<key>ActionBundlePath</key>
<string>/System/Library/Automator/Run AppleScript.action</string>
<key>ActionName</key>
<string>Run AppleScript</string>
<key>ActionParameters</key>
<dict>
<key>source</key>
<string>on run {input, parameters}
display dialog "Will clone " &amp; input &amp; ".
Continue?"
return input
end run</string>
</dict>
<key>BundleIdentifier</key>
<string>com.apple.Automator.RunScript</string>
<key>CFBundleVersion</key>
<string>1.0.2</string>
<key>CanShowSelectedItemsWhenRun</key>
<false/>
<key>CanShowWhenRun</key>
<true/>
<key>Category</key>
<array>
<string>AMCategoryUtilities</string>
</array>
<key>Class Name</key>
<string>RunScriptAction</string>
<key>InputUUID</key>
<string>480BE804-FF18-4B02-8FAE-665A73F6BB64</string>
<key>Keywords</key>
<array>
<string>Run</string>
</array>
<key>OutputUUID</key>
<string>56CB04A2-B1A6-48E1-8E96-7B7519FA9964</string>
<key>UUID</key>
<string>2AF80445-674C-4CA8-A3E8-366D04D7C088</string>
<key>UnlocalizedApplications</key>
<array>
<string>Automator</string>
</array>
<key>arguments</key>
<dict>
<key>0</key>
<dict>
<key>default value</key>
<string>on run {input, parameters}
(* Your script goes here *)
return input
end run</string>
<key>name</key>
<string>source</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>0</string>
</dict>
</dict>
<key>isViewVisible</key>
<true/>
<key>location</key>
<string>396.500000:384.000000</string>
<key>nibPath</key>
<string>/System/Library/Automator/Run AppleScript.action/Contents/Resources/Base.lproj/main.nib</string>
</dict>
<key>isViewVisible</key>
<true/>
</dict>
<dict>
<key>action</key>
<dict>
<key>AMAccepts</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Optional</key>
<true/>
<key>Types</key>
<array>
<string>com.apple.cocoa.string</string>
</array>
</dict>
<key>AMActionVersion</key>
<string>2.0.3</string>
<key>AMApplication</key>
<array>
<string>Automator</string>
</array>
<key>AMParameterProperties</key>
<dict>
<key>COMMAND_STRING</key>
<dict/>
<key>CheckedForUserDefaultShell</key>
<dict/>
<key>inputMethod</key>
<dict/>
<key>shell</key>
<dict/>
<key>source</key>
<dict/>
</dict>
<key>AMProvides</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Types</key>
<array>
<string>com.apple.cocoa.string</string>
</array>
</dict>
<key>ActionBundlePath</key>
<string>/System/Library/Automator/Run Shell Script.action</string>
<key>ActionName</key>
<string>Run Shell Script</string>
<key>ActionParameters</key>
<dict>
<key>COMMAND_STRING</key>
<string>set -ex
repo_dir="${HOME}/Code3rdParty"
code_cmd="/usr/local/bin/code"
if [[ $# -ne 1 ]]; then
echo &gt;&amp;2 "Usage: $0 &lt;git-clone-url&gt;"
exit 1
fi
if ! test -x "$code_cmd"; then
echo &gt;&amp;2 "Requires vs-code command line tool at $code_cmd"
exit 1
fi
main() {
local clone_url=$1
local dir_name="$(basename "${clone_url%.*}")"
local full_dir="${repo_dir}/${dir_name}"
local vscode_workspace="${full_dir}/${dir_name}.code-workspace"
mkdir -p "$repo_dir"
git -C "$repo_dir" clone "$clone_url"
write_workspace_file "$vscode_workspace" "$full_dir"
/usr/local/bin/code -n "$vscode_workspace"
}
write_workspace_file() {
local vscode_workspace_file=$1
local workspace_dir=$2
echo "{\"folders\":[{\"path\": \"${workspace_dir}\"}],
\"settings\": {}}" &gt; "$vscode_workspace_file"
}
main "$@"
</string>
<key>CheckedForUserDefaultShell</key>
<true/>
<key>inputMethod</key>
<integer>1</integer>
<key>shell</key>
<string>/bin/bash</string>
<key>source</key>
<string></string>
</dict>
<key>BundleIdentifier</key>
<string>com.apple.RunShellScript</string>
<key>CFBundleVersion</key>
<string>2.0.3</string>
<key>CanShowSelectedItemsWhenRun</key>
<false/>
<key>CanShowWhenRun</key>
<true/>
<key>Category</key>
<array>
<string>AMCategoryUtilities</string>
</array>
<key>Class Name</key>
<string>RunShellScriptAction</string>
<key>InputUUID</key>
<string>2AE78D62-69AE-48F5-932C-4B71969C23BA</string>
<key>Keywords</key>
<array>
<string>Shell</string>
<string>Script</string>
<string>Command</string>
<string>Run</string>
<string>Unix</string>
</array>
<key>OutputUUID</key>
<string>CD283703-2129-4162-BB2B-E588236D544F</string>
<key>UUID</key>
<string>22118D2C-7856-4E3F-84C6-93E84D98FDF2</string>
<key>UnlocalizedApplications</key>
<array>
<string>Automator</string>
</array>
<key>arguments</key>
<dict>
<key>0</key>
<dict>
<key>default value</key>
<integer>0</integer>
<key>name</key>
<string>inputMethod</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>0</string>
</dict>
<key>1</key>
<dict>
<key>default value</key>
<string></string>
<key>name</key>
<string>source</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>1</string>
</dict>
<key>2</key>
<dict>
<key>default value</key>
<false/>
<key>name</key>
<string>CheckedForUserDefaultShell</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>2</string>
</dict>
<key>3</key>
<dict>
<key>default value</key>
<string></string>
<key>name</key>
<string>COMMAND_STRING</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>3</string>
</dict>
<key>4</key>
<dict>
<key>default value</key>
<string>/bin/sh</string>
<key>name</key>
<string>shell</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>4</string>
</dict>
</dict>
<key>conversionLabel</key>
<integer>0</integer>
<key>isViewVisible</key>
<true/>
<key>location</key>
<string>396.500000:732.000000</string>
<key>nibPath</key>
<string>/System/Library/Automator/Run Shell Script.action/Contents/Resources/English.lproj/main.nib</string>
</dict>
<key>isViewVisible</key>
<true/>
</dict>
</array>
<key>connectors</key>
<dict>
<key>24500C8B-0A88-4DE2-84A0-55DF61C6D106</key>
<dict>
<key>from</key>
<string>2AF80445-674C-4CA8-A3E8-366D04D7C088 - 2AF80445-674C-4CA8-A3E8-366D04D7C088</string>
<key>to</key>
<string>22118D2C-7856-4E3F-84C6-93E84D98FDF2 - 22118D2C-7856-4E3F-84C6-93E84D98FDF2</string>
</dict>
</dict>
<key>workflowMetaData</key>
<dict>
<key>serviceInputTypeIdentifier</key>
<string>com.apple.Automator.text</string>
<key>serviceOutputTypeIdentifier</key>
<string>com.apple.Automator.nothing</string>
<key>serviceProcessesInput</key>
<integer>0</integer>
<key>workflowTypeIdentifier</key>
<string>com.apple.Automator.servicesMenu</string>
</dict>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Clone To VSCode</string>
</dict>
<key>NSMessage</key>
<string>runWorkflowAsService</string>
<key>NSSendTypes</key>
<array>
<string>public.utf8-plain-text</string>
</array>
</dict>
</array>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment