I am using macOS’s /bin/date command, both in Terminal and via AppleScript (do shell script). I noticed inconsistent behaviour with the %N format specifier for nanoseconds:
• On some Macs, date +%s%N returns numeric nanoseconds as expected.
• On other Macs, the same command returns a literal N or fails when coerced to a number.
• This occurs across different macOS versions and on both Intel and Apple Silicon machines.
My understanding is that macOS ships BSD date, which does not officially document %N. I am trying to determine:
1. Is %N in /bin/date officially supported on macOS, and if so, on which versions?
2. If %N is not supported, what is Apple’s recommended, portable method for obtaining sub-second or millisecond timestamps in shell scripts or AppleScript across all macOS versions?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi all. Title says it all really. I have an app on MacOS that sends multicast UDP to multiple iOS devices. It shows realtime bar numbers of music played back by a playback software. It was all working until I tried a direct ethernet connection between Mac and phone - a scenario that would be quite common in the theatre world where machines dont have internet connection and people dont rely on wifi. How can I choose which interface my app sends the data through? Here is my connection function:
func openConnection() {
let params = NWParameters.udp
params.allowLocalEndpointReuse = true
params.includePeerToPeer = true
let endpoint = NWEndpoint.hostPort(host: host, port: port)
let conn = NWConnection(to: endpoint, using: params)
self.connection = conn
conn.stateUpdateHandler = { state in
switch state {
case .ready:
print("Multicast connection ready to \(self.host)")
UDPClient.console.log("Multicast connection ready to \(self.host)")
case .failed(let error):
print("Multicast connection failed: \(error)")
default:
break
}
}
let udpQueue = DispatchQueue(label: "UDPClientQueue")
conn.start(queue: udpQueue)
}
Thanks for any help in advance!
Topic:
App & System Services
SubTopic:
Networking