Post

Replies

Boosts

Views

Activity

Creating headers in Apple Mail using AppleScript
My grand plan is to have a rule in Apple Mail that automatically adds a custom header to each message. This rule would be last and each of the rules before that last rule would check for the presence of this custom header and therefore no longer work for incoming mail. So the plan is to have a small AppleScript that adds this header but I am running into a block which hopefully someone can help we with. I have the following pieces of code: tell application "Mail" activate set myHeader to make new header with properties {name:"X-MySecretHeader", content:"It's been set"} end The last statement fails with the following error: Mail got an error: Can’t make or move that element into that container. I then changed the code slightly: tell application "Mail" activate set theMessage to get item 1 of (get selection) set theHeaders to headers of theMessage set myHeader to duplicate item -1 of theHeaders end Mail got an error: Headers can not be copied. That last error seems to indicate that I'm trying to do something which cannot be done. I have also tried to do this in a tell block to theMessage but that did not change anything. Anyone has an idea?
0
0
642
Dec ’23
Enable Inspector in WKWebView under SwiftUI & SplitView
I am running this on MacOS, Xcode version 11.6. In order to run this code you must add com.apple.security.network.client with the value true to your entitlements file. I want to enable the Inspector for WKWebView. I have created an NSViewRepresentable to encapsulate the WKWebView. Here is the simplified code: struct WKWebViewRepresentable: NSViewRepresentable { 		var urlToDisplay: URL? 		var enableDeveloperTools: Bool = false 		func loadData(wkWebView: WKWebView) { 				if let url = urlToDisplay { 						wkWebView.load(URLRequest(url: url)) 				} 		} 		func makeNSView(context: Context) -> WKWebView { 				let wkWebView = WKWebView() 				wkWebView.configuration.preferences.setValue(enableDeveloperTools, forKey: "developerExtrasEnabled") 				loadData(wkWebView: wkWebView) 				return wkWebView 		} 		func updateNSView(_ wkWebView: WKWebView, context: Context) { 				loadData(wkWebView: wkWebView) 		} 		func makeCoordinator() -> Coordinator { 				return Coordinator(self) 		} } extension WKWebViewRepresentable { 		class Coordinator: NSObject { 				init(_ parent: WKWebViewRepresentable) { 						super.init() 				} 		} } and with this code in place I can create the following ContentView: struct ContentView: View { 		static let demoURL = "https://" + "www.apple.com/apple-music/" 		var body: some View { 				HStack { 						WKWebViewRepresentable(urlToDisplay: URL(string: ContentView.demoURL), enableDeveloperTools: true) 						WKWebViewRepresentable(urlToDisplay: URL(string: ContentView.demoURL), enableDeveloperTools: false) 				} 		} } The good news is that the above code actually works. If you right click on the left hand side, you can select Inspect Element which will start the Inspector. The idea is that I would do discovery on the left hand side and do show the processed result on the right hand side. That part is obviously not in the code. For testing purposes the right hand side simply shows the same content as the left hand side. I would like to see that the user is being able to split the real-estate between the two views, hence I replace the HStack with HSplitView, no other change. When you run this code, the WkWebView's come up as before but one you select Inspect Element the place where the Inspector should show is blank (black or white depending on dark mode), it starts flashing etc. By dragging inside that rectangle, it becomes clear that the code is actually running just not properly rendering. This stackoverflow - https://stackoverflow.com/questions/60727065/wkwebview-web-inspector-in-macos-app-fails-to-render-and-flickers-flashes article, mentions the same problem and it suggests that autolayout should be disabled. Does anyone know a trick to circumvent this layout problem for SwiftUI?
1
0
4k
Aug ’20