• 4 Posts
  • 13 Comments
Joined 1 year ago
cake
Cake day: October 6th, 2023

help-circle






  • A year ago, u/vsavchenko announced https://www.reddit.com/r/emacs/comments/wemj1z/writing_emacs_dynamic_modules_in_swift. I had been meaning to try it out for some time. Finally had the chance and it’s really neat!

    For example, most of the sharing logic from the experiment in the screen grab is below:

    try env.defun(
      "macos-module--share",
      with: """
        Share files in ARG1.
    
        ARG1 must be a vector (not a list) of file paths.
        """
    ) { (env: Environment, files: [String]) in
      let urls = files.map { URL(fileURLWithPath: $0) }
    
      let picker = NSSharingServicePicker(items: urls)
      guard let view = NSApp.mainWindow?.contentView else {
        return
      }
    
      let x = try env.funcall("macos--emacs-point-x") as Int
      let y = try env.funcall("macos--emacs-point-y") as Int
    
      let rect = NSRect(
        x: x + 15, y: Int(view.bounds.height) - y + 15, width: 1, height: 1
      )
      picker.show(relativeTo: rect, of: view, preferredEdge: .maxY)
    
      return
    }
    








  • As a macOS user, I typically glue these dired things via dwim-shell-command (disclosure, I wrote that).

    Not super tested, but I added dwim-shell-commands-macos-add-to-photos to dwim-shell-commands.el (the optional part of the package).

    (defun dwim-shell-commands-macos-add-to-photos ()
      "Add to Photos.app."
      (interactive)
      (dwim-shell-command-on-marked-files
       "Add to Photos.app"
       "osascript <>\"
      end tell
    EOF"
       :silent-success t
       :utils "osascript"
       :on-completion (lambda (buffer process)
                        (if-let ((success (= (process-exit-status process) 0)))
                            (start-process "Open Photos" nil "open" "-a" "Photos")
                          (switch-to-buffer buffer)))))
    
    1. Select 1 or multiple photos from dired
    2. M-x dwim-shell-commands-macos-add-to-photos

    ps. This also works on current buffer if you’re viewing an image in a buffer.