Last active
May 10, 2018 11:32
-
-
Save fumiyas/bbe8741cbc68da3caafe0590e1287c87 to your computer and use it in GitHub Desktop.
Copy and remove a file or directory by macOS Finder application
This file contains hidden or 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
| #!/bin/bash | |
| ## | |
| ## Copy a file or directory by macOS Finder application | |
| ## Copyright (c) 2018 SATOH Fumiyasu @ OSS Technology Corp., Japan | |
| ## | |
| ## License: GNU General Public License version 3 | |
| ## | |
| set -u | |
| if [[ $# -ne 2 ]]; then | |
| echo "Usage: $0 SRC DST" | |
| exit 1 | |
| fi | |
| path2abs() { | |
| if [[ $1 != /* ]]; then | |
| printf '%s' "$PWD/$1" | |
| else | |
| printf '%s' "$1" | |
| fi | |
| } | |
| src=$(path2abs "$1"); shift | |
| dst=$(path2abs "$1"); shift | |
| /usr/bin/osascript - "$src" "$dst" <<'EOF' | |
| on run argv | |
| set srcPath to POSIX file (item 1 of argv) | |
| set dstDir to POSIX file (item 2 of argv) | |
| with timeout of 0 seconds | |
| tell application "Finder" | |
| #activate | |
| duplicate srcPath to folder dstDir | |
| end tell | |
| end timeout | |
| end run | |
| EOF |
This file contains hidden or 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
| #!/bin/bash | |
| ## | |
| ## Remove a file or directory by macOS Finder application | |
| ## Copyright (c) 2018 SATOH Fumiyasu @ OSS Technology Corp., Japan | |
| ## | |
| ## License: GNU General Public License version 3 | |
| ## | |
| set -u | |
| if [[ $# -ne 1 ]]; then | |
| echo "Usage: $0 TARGET" | |
| exit 1 | |
| fi | |
| path2abs() { | |
| if [[ $1 != /* ]]; then | |
| printf '%s' "$PWD/$1" | |
| else | |
| printf '%s' "$1" | |
| fi | |
| } | |
| target=$(path2abs "$1"); shift | |
| /usr/bin/osascript - "$target" <<'EOF' | |
| on run argv | |
| set targetPath to POSIX file (item 1 of argv) | |
| with timeout of 0 seconds | |
| tell application "Finder" | |
| #activate | |
| if kind of (info for targetPath) is "folder" then | |
| delete (files of folder targetPath) | |
| end if | |
| delete targetPath | |
| end tell | |
| end timeout | |
| end run | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment