You can check for a specific UTI but "public.json" doesn't seem to be supported by default.
What you could do is something like this
Code: Select all
; Get general pasteboard
Global Pasteboard = CocoaMessage(0, 0, "NSPasteboard generalPasteboard")
; Create a NSArray with a "public.json" string object
Global TypeJSON = CocoaMessage(0, CocoaMessage(0, 0, "NSArray alloc"), "initWithObject:$", @"public.json")
; Procedure to check if pasteboard contains JSON data
Procedure.i Pasteboard_ContainsJSON()
ProcedureReturn CocoaMessage(0, Pasteboard, "canReadItemWithDataConformingToTypes:", TypeJSON)
EndProcedure
; Procedure to get JSON data from clipboard
Procedure.s Pasteboard_GetJSON()
Protected JSONString.i = CocoaMessage(0, Pasteboard, "stringForType:$", @"public.json")
If JSONString
ProcedureReturn PeekS(CocoaMessage(0, JSONString, "UTF8String"), -1, #PB_UTF8)
Else
ProcedureReturn ""
EndIf
EndProcedure
; Procedure to set JSON data on the clipboard
Procedure Pasteboard_SetJSON(JSON.s)
CocoaMessage(0, Pasteboard, "declareTypes:", TypeJSON, "owner:", #nil)
CocoaMessage(0, Pasteboard, "setString:$", @JSON, "forType:$", @"public.json")
EndProcedure
; Test
Pasteboard_SetJSON("[1, 3, 5, 7, null, 23, 25, 27]")
If Pasteboard_ContainsJSON()
Debug Pasteboard_GetJSON()
EndIf
There are no notifications available but if you want to check the pasteboard with a timer like for example two times a second, you can first check changeCount.
Code: Select all
CocoaMessage(0, Pasteboard, "changeCount")
Every time something changes to the pasteboard, this value is increased.
That way you only have to check in more detail if this value has changed in between.