Hi!
I wrote a backup program in Swift which is used for several servers. It does send an email each day about the backup status.
Currently I use /usr/bin/mail because it works well with via postfix configuration.
Now I need to add an attachment (an image about the access statistics) and this is not possible using the mail command.
I looked at the docs and I found
NSSharingService(named: NSSharingService.Name.composeEmail)
but it does just create a mail which is opened in Mail.app.
Is there really no OS provided way to send an SMTP mail without any user interaction?
I don't want to implement a 3rd party SMTP-Library.
TIA,
GreatOm
Post
Replies
Boosts
Views
Activity
Hi!
I need a clue how to solve this issue.
I can't build a universal command line app on my new MacBook Pro. I use Swift with some Swift packages and get the error
Could not find module 'NIO' for target 'x86_64-apple-macos'; found: arm64, arm64-apple-macos, at: BUILDPATH
Where do I have to look in Xcode (v 13.1) to get universal packages?
Hi!
I wrote a backup console application. It does use ssh/sshfs to access a web server via public key. Also it does send an SMTP-mail when finished.
If the process is started via
launchctl load DAEMON
it works always properly (RunAtLoad is true).
But when the daemon is called automatically at night it does not always work. In my log I get these errors:
ssh: connect to host SERVERURL port 22: Undefined error: 0
and
Failed sending: NIOConnectionError(host: "mail.mydomain", port: 25, dnsAError: Optional(NIOCore.SocketAddressError.unknown(host: "mail.mydomain", port: 25)), dnsAAAAError: Optional(NIOCore.SocketAddressError.unknown(host: "mail.mydomain", port: 25)), connectionErrors: [])
it does run on a MacMini M1 with macOS 12.2.
Any clue what's wrong or how to find the reason of this issue?
PS. On another MacMini (Intel) with macOS 11.6 the backup works since a year but there is always an admin user logged in.
Hi!
I have an issue calling mount_smbfs with a user from a specific domain. A sample shell call is
mount_smbfs -N -o nodev,nosuid "//DOMAIN;USER:PASS@SERVER_ADDRESS" /SOMEPATH
Using the code below I get an invalid command because the semicolon ends the command in shell.
var server = "//DOMAIN;USER:PASS@SERVER_ADDRESS"
let remotePath = "/REMOTEPATH"
let localPath = "/LOCALPATH"
let cmd = Process()
cmd.executableURL = URL(fileURLWithPath: "/sbin/mount_smbfs")
cmd.arguments = ["-N", "-o nodev,nosuid", "\(server)\(remotePath)", localPath]
Using a quoted semicolon
var server = "//DOMAIN\;USER:PASS@SERVER_ADDRESS"
does also not work, because the backslash is quoted to DOMAIN\\;USER automatically via Process class. So I end up with two backslash.
Using quotes did also not work for me.
Any clue how to solve this issue?
I wrote a little test app which must also run on some older Macs still using macOS 10.14.6.
When I copy the app to the old Mac I get following error message:
You can’t use this version of the application “APPNAME” with this version of macOS.
You have macOS 10.14.6. The application requires macOS 10.14 or later.
It seems to be a build bug…
I use Xcode 13.3 on macOS 12.3.1.
Any clue how to solve this issue?
I made a test with a new XIB-based project using this code
func applicationDidFinishLaunching(_ aNotification: Notification) {
guard let content = window.contentView else {
print("Error: cannot access windows contentview!")
return
}
let tv = NSTextView(frame: NSMakeRect(100, 300, 200, 40))
tv.string = "Text subview"
tv.font = NSFont.systemFont(ofSize: 30.0)
content.addSubview(tv)
let chartView = NSHostingView(rootView: myChart())
chartView.setFrameSize(content.frame.size)
content.addSubview(chartView)
content.printView(self)
}
"myChart" is s sample view using Charts.
The window does show the text and the chart but the print shows the text only.
How can I get the SwiftUI-View printed?
My goal is a PDF output of a SwiftUI view.
There are already several older threads with similar questions but no solution, yet.
Using a simple script to get the EXIF-information from a photo
tell application "Image Events"
set theOpenFile to open "/PATH/TO/IMAGE.HEIC"
set theTags to name of metadata tags of theOpenFile
close theOpenFile
return theTags
end tell
I get for the same image (from an iPhone) following results
macOS 13.2
{"format", "hasAlpha", "formatOptions", "typeIdentifier", "dpiHeight", "dpiWidth", "path"}
macOS 10.14.6 (Mojave)
{"samplesPerPixel", "hasAlpha", "dpiHeight", "dpiWidth", "bitsPerSample", "profile", "formatOptions", "ExifColorSpace", "pixelHeight", "path", "creation", "software", "space", "pixelWidth", "format", "make", "model", "typeIdentifier"}
So it is no longer possible to read the image meta data using AppleScript on macOS Ventura, i.e. the creation date.
Hi!
I have a strange error in my SwiftUI app and need a clue how to solve this issue.
I work on a timetable like app where I hold the data in the App struct
@StateObject private var appData = VorlesungsHandler()
and the classes are defined as
public class VorlesungsHandler : ObservableObject {
let dayList : [Weekdays] = [.Montag, .Dienstag]
@Published var vorlesungen : [Vorlesung] = [ Vorlesung(…), … ]
…
}
and
class Vorlesung : Hashable, Equatable, Identifiable, ObservableObject {
@Published var subject: ModuleType
@Published var person : Personen
let vID = UUID()
…
}
The appData object is passed down to the views and subviews via
.environmentObject(appData)
and it seems to work well.
Now I face an error when I change the array „vorlesungen“ in Appdata via
func updateVorlesung(oldID : UUID?, newV : Vorlesung) {
if oldID == nil {
self.vorlesungen.append(newV)
return
}
for i in 0..<self.vorlesungen.count {
if self.vorlesungen[i].vID == oldID! {
self.vorlesungen.remove(at: i)
self.vorlesungen.append(newV)
break
}
}
}
The error message is
Fatal error: Duplicate keys of type 'Vorlesung' were found in a Dictionary.
This usually means either that the type violates Hashable's requirements, or that members of such a dictionary were mutated after insertion.
This error does not occur every time but 30 to 50% of the changes.
In my tests I did also add
self.objectWillChange.send()
in front of all array-change commands but it does not help.
Any clue how to solve this issue?
Hi!
I have a strange issue for my SwiftUI based App on macOS.
Opening and saving a file works well when the app is already open.
But when I double click a file in Finder to launch the App the file is not opened.
When I double click the file again it gets loaded.
I assume that I missed something simple but I can't get a clue from documentation and internet searching.
Any clue how to proceed to open a file on application launch?
Hi!
I write a time table like app where entries on a day planner are created and modified.
It works well but since the latest additions I get random crashes after clicking an UI control.
Any clue how to debug such an issue?
The crash log looks like this:
Code Type: ARM-64 (Native)
Parent Process: launchd [1]
OS Version: macOS 13.3 (22E252)
Report Version: 12
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000019472f6f4
Termination Reason: Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process: exc handler [2623]
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libswiftCore.dylib 0x19472f6f4 _assertionFailure(_:_:flags:) + 188
1 libswiftCore.dylib 0x19488f8d4 KEY_TYPE_OF_DICTIONARY_VIOLATES_HASHABLE_REQUIREMENTS(_:) + 208
2 libswiftCore.dylib 0x1947d8868 _NativeDictionary._unsafeInsertNew(key:value:) + 316
3 libswiftCore.dylib 0x194890b08 _NativeDictionary.extractDictionary(using:count:) + 740
4 libswiftCore.dylib 0x194892364 closure #1 in _NativeDictionary.filter(_:) + 780
5 libswiftCore.dylib 0x1947bcdf0 _NativeDictionary.filter(_:) + 260
6 libswiftCore.dylib 0x1947bc8b0 Dictionary.filter(_:) + 3004
7 SwiftUI 0x1ae872e30 0x1adcb1000 + 12328496
8 SwiftUI 0x1adea10c8 0x1adcb1000 + 2031816
9 SwiftUI 0x1adeae364 0x1adcb1000 + 2085732
10 SwiftUI 0x1ae053c08 0x1adcb1000 + 3812360
11 SwiftUI 0x1ae052550 0x1adcb1000 + 3806544
12 SwiftUI 0x1ae050c34 0x1adcb1000 + 3800116
13 SwiftUI 0x1ae15e980 0x1adcb1000 + 4905344
14 AttributeGraph 0x1af552cec AG::Graph::UpdateStack::update() + 520
15 AttributeGraph 0x1af553494 AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) + 424
16 AttributeGraph 0x1af5615d8 AG::Subgraph::update(unsigned int) + 864
17 SwiftUI 0x1af131174 0x1adcb1000 + 21496180
18 SwiftUI 0x1af1325fc 0x1adcb1000 + 21501436
19 SwiftUI 0x1ae315204 0x1adcb1000 + 6701572
20 SwiftUI 0x1aee53c68 0x1adcb1000 + 18492520
21 SwiftUI 0x1aee5278c 0x1adcb1000 + 18487180
22 SwiftUI 0x1ae3151c4 0x1adcb1000 + 6701508
23 SwiftUI 0x1af1325c4 0x1adcb1000 + 21501380
24 SwiftUI 0x1af1324b0 0x1adcb1000 + 21501104
25 SwiftUI 0x1ae828ce8 0x1adcb1000 + 12025064
26 SwiftUI 0x1aef15914 0x1adcb1000 + 19286292
27 SwiftUI 0x1aef1885c 0x1adcb1000 + 19298396
28 SwiftUI 0x1aef188b4 0x1adcb1000 + 19298484
29 CoreFoundation 0x185b09ac4 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
30 CoreFoundation 0x185b099b0 __CFRunLoopDoObservers + 532
31 CoreFoundation 0x185b085e8 CFRunLoopRunSpecific + 704
32 HIToolbox 0x18f33ddf4 RunCurrentEventLoopInMode + 292
33 HIToolbox 0x18f33da84 ReceiveNextEventCommon + 220
34 HIToolbox 0x18f33d988 _BlockUntilNextEventMatchingListInModeWithFilter + 76
35 AppKit 0x188d27f58 _DPSNextEvent + 636
36 AppKit 0x188d270f4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 716
37 AppKit 0x188d1b558 -[NSApplication run] + 464
38 AppKit 0x188cf29a8 NSApplicationMain + 880
39 SwiftUI 0x1add4d974 0x1adcb1000 + 641396
40 SwiftUI 0x1aeeacfa0 0x1adcb1000 + 18857888
41 SwiftUI 0x1ae72e43c 0x1adcb1000 + 10998844
42 ITR-Stundenplan 0x100eabec8 static ITR_StundenplanApp.$main() + 40 (ITR_StundenplanApp.swift:18)
43 ITR-Stundenplan 0x100eac4c8 main + 12
44 dyld 0x1856d3f28 start + 2236
I made a log analyzer which does currently use the SHELL which works fine.
Now I wanted to replace it with native Swift code but the result is really slow.
Here is an example with about 100 MB real log data. It needs just a second via SHELL but more than 80 seconds with Swift code.
Is there a way to improve the Swift code?
In SHELL I use
% time (cd /regTest/logs;cat access.log access.log.1 | grep '26\/Apr' | egrep -v '(www.apple.com/go/applebot | www.bing.com/bingbot.htm | www.googlebot.com/bot.html | Xing Bot)' | awk '/GET/ {print $1}' | sort -n | uniq 1>/dev/null)
1,09s user 0,05s system 105% cpu 1,081 total
Here is the result of my Swift test:
% time ./regTest
Found 1813 lines.
82,54s user 0,26s system 99% cpu 1:22,83 total
My Swift sample code
import Foundation
import RegexBuilder
guard let fullText = try? String(contentsOf: URL(filePath: "/regTest/logs/access.log")) + String(contentsOf: URL(filePath: "/regTest/logs/access.log.1")) else {
print("Cannot read files!")
exit(1)
}
let yesterdayRegEx = Regex {
Capture {
"26/Apr"
}
}
let botListRegEx = Regex {
Capture {
ChoiceOf {
"www.apple.com/go/applebot"
"www.bing.com/bingbot.htm"
"www.googlebot.com/bot.html"
"Xing Bot"
}
}
}
let dateMatch = fullText.split(separator: "\n")
.filter{ $0.firstMatch(of: yesterdayRegEx) != nil }
.filter{ $0.firstMatch(of: botListRegEx) == nil }
print("Found \(dateMatch.count) lines.")
I have an animation depending on a range. When the end is reached the value is reseted to 0.
Unfortunately I get a "rollback" animation which looks very bad but I have no idea how to handle it.
Here is a sample code:
import SwiftUI
let clockTimer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
struct ContentView: View {
static func getSecond(_ d : Date) -> Int {
let dc = Calendar.current.dateComponents([.second], from: d)
guard let s = dc.second else {
fatalError("Can't get value!")
}
return s
}
@State var s = ContentView.getSecond(Date())
var body: some View {
ZStack {
Rectangle()
.fill(.white)
.frame(width: 200.0, height: 200.0)
Rectangle()
.fill(.red)
.frame(width: 80.0, height: 1.5, alignment: .center)
.offset(CGSize(width: 50, height: 0))
.rotationEffect(Angle(degrees: 360.0 / 60.0 * Double(s) - 90.0))
.animation(.smooth, value: s)
}
.onReceive(clockTimer) { currentDate in
s = ContentView.getSecond(currentDate)
}
}
}
#Preview {
ContentView()
}
Any clue how to solve this issue?
We are used to use a SMB-based network homedir for students in our labs. Unfortunately this does no longer work with current macOS versions (Apple case 101442640823).
Therefore we need a workaround.
My idea is to use a standard user account which is reseted daily. Therefore I created "USER" and made the initial setup after the first login.
My plan was to create a tar-active and a launchdaemon script which does remove /Users/USER and extract the tar archive to get a fresh USER home.
This does not work:
I cannot remove as root the old home dir via "rm -rf /Users/USER" due to permission errors.
I want not remove and re-create the user via dscl because the initial first login setup should not be needed every day. I want to reset USERS home to an archived backup of a defined status.
Any clue how to solve this issue?
We'd like to use a custom setup for our new students via a modified User Template folder.
On macOS 14 the new user template is located at
/Library/User Template/Non_localized
I can add e.g. another folder here (as "root"):
drwxr-xr-x 2 root wheel 64 8 Apr 13:58 newFolder
And when a new user is created this folder is added to users homedir, as expected.
But this folder has an additional unexpected ACL:
$ ls -lde newFolder
drwx------+ 2 newuser staff 64 8 Apr 13:59 newFolder
0: group:everyone deny delete
Is there any documentation about the user template handling for current macOS versions?
We are specially interested in
How are ACLs added
Predefining standard preferences (e.g. connected servers are visible on desktop)
Ayn clue here?