Sleep shortcut - Working Template
COMMENT
Created by @jacksondame
This base template provides the building blocks for exporting a single health category out of Apple Health and into a CSV format
TEXT
Sleep Start, Sleep End

Text
VARIABLES
Set variable
health data
to
Text
HEALTH
Find
All Health Samples
where
All the following are true [{'class': 'filter-property', 'value': 'Type'}, {'class': 'filter-operator', 'value': 'is'}, {'class': 'filter-benchmark', 'value': 'Sleep'}] [{'class': 'filter-property', 'value': 'Start Date'}, {'class': 'filter-operator', 'value': 'is in the last'}, {'class': 'filter-benchmark', 'value': '3', 'glyph': '', 'UUID': ''}, {'class': 'filter-unit', 'value': 'days', 'glyph': '', 'UUID': ''}] [{'class': 'filter-property', 'value': 'Value'}, {'class': 'filter-operator', 'value': 'is'}, {'class': 'filter-benchmark', 'value': 'Asleep'}] [{'class': 'filter-property', 'value': 'Source'}, {'class': 'filter-operator', 'value': 'is not'}, {'class': 'magic empty', 'value': 'Value', 'glyph': '', 'UUID': ''}]

Health Samples
SCRIPTING
Repeat with each item in
Health Samples

Repeat Results
HEALTH
Get
Source
from
Repeat Item

Source
DOCUMENTS
Get text from
Source

Text
HEALTH
Get
Value
from
Repeat Item

Value
HEALTH
Get
Start Date
from
Repeat Item

Start Date
CALENDAR
Format
Start Date
Options Under Construction

Formatted Date
HEALTH
Get
End Date
from
Repeat Item

End Date
CALENDAR
Format
End Date
Options Under Construction

Formatted Date
TEXT
Type
;
Source
;
Formatted Date
,
Formatted Date

Text
SCRIPTING
End Repeat

Repeat Results
TEXT
Combine
Repeat Results
with
New Lines

Combined Text
TEXT
Combined Text
health data

Text
DOCUMENTS
Show
Text
in Quick Look
Showcuts