Script to start recording and copy to clip board

I have been trying to modify a script which should help me to start a recording and copy paste the file to clipboard. However, when I try to copy I only get this, instead of a recording audio file. [file:///Users/yoosuk/Library/Group Containers/group.com.apple.VoiceMemos.shared/Recordings/](file:///Users/yoosuk/Library/Group%20Containers/group.com.apple.VoiceMemos.shared/Recordings/)

set appName to "VoiceMemos"
if application appName is running then
    tell application id (id of application appName)
        quit
    end tell
    copy {do shell script "echo $HOME"} to {homeFolder}
    set recordingsFolder to homeFolder & "/Library/Group Containers/group.com.apple.VoiceMemos.shared/Recordings"
    set audioFileName to (do shell script "cd " & quoted form of recordingsFolder & " && ls -ltr -A1 | grep m4a | tail -1")
    set the clipboard to POSIX file (recordingsFolder & "/" & audioFileName)
else
    tell application id (id of application appName) to activate
    tell application "System Events"
        set limit to 10
        set counter to 0
        repeat
            if exists window 1 of process appName then exit repeat
            if (counter > limit) then exit repeat
            set counter to counter + 1
            delay 1
        end repeat
        perform action "AXRaise" of window 1 of process appName
        keystroke "n" using command down
    end tell
end if

It seems to be a permission error. When I isolate do shell script "ls -ltr -A1 " & quoted form of recordingsFolder, I get an “Operation not permitted error”. The error goes away once I give Script Editor full disk access in Settings->Privacy & Security. After doing that, your original script works as expected.