-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfittime
executable file
·47 lines (41 loc) · 1.23 KB
/
fittime
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
#######################################################################
# Made by : Ewoud Dronkert
# Licence : GNU GPL v3
# Platform : Mac OS X
# Requires : Bash, xattr
# Location : ~/bin/
# Name : fittime
# Version : 1.0.0
# Date : 2015-11-17
# Purpose : Align timestamps with file names for Garmin .fit files.
# Also remove DOS 'execute' and OS X extended attributes.
# Parameters : none
# Settings : FITDIR = location of Garmin Activity .fit files
# Exit 0 : No errors (but chmod/xattr/touch errors not monitored)
# 1 : FITDIR not found or not a directory
# 2 : No .fit files in FITDIR directory
#######################################################################
FITDIR=~/Documents/Garmin\ Activities
if [ ! -d "$FITDIR" ]; then
echo "FIT-file directory not found: $FITDIR" 1>&2
exit 1
fi
n=$(ls "$FITDIR"/*.fit | grep -E '\.fit$' | wc -l | grep -oE '\d+')
if (( n >= 1 )); then
echo "FIT-files found: $n"
else
echo "No FIT-files found in directory: $FITDIR" 1>&2
exit 2
fi
m=0
for f in "$FITDIR"/*.fit; do
t=${f:(-23)}
t=${t//-/}
t=${t:0:12}.${t:12:2}
chmod 600 "$f"
xattr -c "$f"
touch -t $t "$f" && (( m++ ))
done
echo "FIT-files touched: $m"
exit 0