Skip to content

Instantly share code, notes, and snippets.

View porg's full-sized avatar

porg

View GitHub Profile
@porg
porg / link2file.sh
Last active June 1, 2022 23:09
link2file.sh - Replaces macOS alias or symlink with the file it points to
#!/bin/sh
# link2file /path/to/item1 /path/to/item2 …
#
# - Checks per each item that is is a macOS alias or a symlink and its target is a regular file
# - Replaces each alias or symlink with the file it points to
# - Names the newly created file with the filename of the alias/symlink it replaces
# - and if that alias has no extension, uses the extension of the file it points to
# - and if that file has no extension either, the newly created file has none too.
# - Is fast and space-efficient on APFS (copy-on-write).
@porg
porg / macos-ouch-modification-or-creation-or-both.md
Created May 30, 2022 10:27
On macOS touch a file modification date or creation date or both

Touch a file modification date or creation date or both

Syntax

  • touch <file> → Changes the modification date of file to NOW.
  • touch -a <file> → Changes the access date of file to NOW.
  • touch-c <file> → Changes the creation date of file to NOW.
  • touch-cm <file> → Changes both the creation date and the modification date of file to NOW.

Setup

@porg
porg / cp-date-modified.sh
Created January 20, 2022 22:17
Copy modification date from all files of source directory to same named files at destination directory if existing there
#!/bin/bash
if [[ -z "$1" || -z "$2" || "$1" == "-h" || "$1" == "--help" ]] ; then
cat <<EOF
USAGE: `basename $0` backupDir targetDir
Loops through all files on root level of backupDir.
For each file in backupDir it tries to find a same named file in targetDir.
- If not found in target (because renamed or removed meanwhile) the file is skipped.
- If found and they have the same modification timestamp nothing is done either.
@porg
porg / archive-order-to-metadata.sh
Last active March 25, 2022 16:21
File order in archive will be baked into metadata of extracted files
#!/bin/bash
# https://github.com/aonez/Keka/issues/932#issuecomment-989762514
# By Matt Sephton @gingerbeardman 2021-12-11
# - Created all versions til then
# By @porg 2021-12-16
# + Hiding file extension on all extracted files
# + Setting creation and modification date of output directory
# Dependencies: p7zip, pipx, osxmetadata, SetFile (ships with Xcode)
@porg
porg / archive-order-to-date-modified
Last active December 15, 2021 17:57
Encode the file order in an archive to the metadata of the decompressed files
#!/bin/bash
# https://github.com/aonez/Keka/issues/932#issuecomment-989762514
# By Matt Sephton @gingerbeardman 2021-12-11
# - Created all versions til then
# By @porg 2021-12-15
# - Fixed base60 vs. base100 timestamp bug
# - Added more verbose script output
# Dependencies: p7zip, pipx, osxmetadata