Reputation: 1
I'm looking to perform copy/paste operations with Swift with audio clips on MacOS. This can be done using Finder by right clicking on an audio clip, selecting copy, and then pasting it.
Currently, when an audio file is copied, it is sent to the default system-wide clipboard, which can be accessed through Finder > Edit > Show Clipboard. When viewing the clipboard, I see the title of the audio file (not path) in the main clipboard field, and a footer displaying "Clipboard contents: text / items" at the bottom.
I want to replicate this behaviour with Swift, so I figure that I should use the NSPasteboard.general instance, as it would allow me to modify the contents of the clipboard.
This is what I have so far when it comes to copying an item to the clipboard:
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(audioPath.absoluteString, forType: .URL)
However, this results in an empty main clipboard field, and a footer that displays "Clipboard contents: unknown".
I also tried doing:
let audio = try Data(contentsOf: path)
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setData(audio, forType: .sound)
But the clipboard would display the same message.
How could I programmatically recreate Finder's copy/pasting ability using Swift?
Upvotes: 0
Views: 627