While waiting for Apple to fix Watched Notes-

Well, given that context, let’s start with a small experiment, to see whether we have a basis for a direct import into Tinderbox.

What happens if you run this AppleScript fragment in Script Editor ?

(Or rather, what, if anything, do you see in the Results panel at the foot of Script Editor – you may need to click the small icon for ‘Show or hide the log’ to reveal the results panel)

(Copy and paste the whole of this code, scrolling right down to the last line at end mReturn)

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions


on run
    tell application "Notes"
        set refNotes to a reference to (notes where password protected is false)
        set values to {its name, its body, its creation date, its modification date} of refNotes
        set tuples to my transpose(values)
    end tell
end run


-- transpose :: [[a]] -> [[a]]
on transpose(rows)
    script cols
        on |λ|(_, iCol)
            script cell
                on |λ|(row)
                    item iCol of row
                end |λ|
            end script
            concatMap(cell, rows)
        end |λ|
    end script
    map(cols, item 1 of rows)
end transpose


-- concatMap :: (a -> [b]) -> [a] -> [b]
on concatMap(f, xs)
    set lng to length of xs
    set acc to {}
    tell mReturn(f)
        repeat with i from 1 to lng
            set acc to acc & (|λ|(item i of xs, i, xs))
        end repeat
    end tell
    return acc
end concatMap

-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
    -- The list obtained by applying f
    -- to each element of xs.
    tell mReturn(f)
        set lng to length of xs
        set lst to {}
        repeat with i from 1 to lng
            set end of lst to |λ|(item i of xs, i, xs)
        end repeat
        return lst
    end tell
end map


-- mReturn :: First-class m => (a -> b) -> m (a -> b)
on mReturn(f)
    -- 2nd class handler function lifted into 1st class script wrapper. 
    if script is class of f then
        f
    else
        script
            property |λ| : f
        end script
    end if
end mReturn
1 Like