- Understand what Mac privacy behaviour is and what all APIs Mac is providing to tackle this
- Come up with an explainer which lists down change proposals with screenshots regarding
Mac privacy announcement: https://developer.apple.com/documentation/updates/appkit#macOS-pasteboard-privacy Bug: https://issues.chromium.org/issues/417767133
This is a simple macOS application written in Objective-C++ that demonstrates basic clipboard operations (copy and paste) with a text input field to investigate changes in Pasteboard privacy configuration on Mac.
- macOS (tested on M2)
- Xcode Command Line Tools (provides clang and other necessary build tools)
- Ensure you have latest MacOS version which has the new Pasteboard privacy preview
To install Xcode Command Line Tools, open Terminal and run:
xcode-select --install
defaults write com.example.ClipboardApp EnablePasteboardPrivacyDeveloperPreview -bool yes defaults write org.chromium.Chromium EnablePasteboardPrivacyDeveloperPreview -bool yes
-
Navigate to the project directory: Open Terminal and change to the directory where you saved the source files (
AppDelegate.h
,AppDelegate.mm
,main.mm
).cd /path/to/your/mac_test_clipapp
-
Compile the source code: Use clang++ to compile the Objective-C++ files and link against the Cocoa framework. This command will create an executable file named
ClipboardApp
.clang++ -std=c++17 -fobjc-arc -framework Cocoa main.mm AppDelegate.mm -o ClipboardApp
Explanation of the compile command:
clang++
: The C++ compiler (part of Clang/LLVM).-std=c++17
: Specifies the C++ standard to use (C++17 in this case).-fobjc-arc
: Enables Automatic Reference Counting (ARC) for Objective-C objects, which helps manage memory automatically.-framework Cocoa
: Links the Cocoa framework, which provides the necessary classes for building macOS GUI applications (NSWindow, NSButton, NSTextField, etc.).main.mm AppDelegate.mm
: The source files to compile.-o ClipboardApp
: Specifies the name of the output executable file.
- ** Enable Pasteboard privacy for this app **
defaults write com.example.ClipboardApp EnablePasteboardPrivacyDeveloperPreview -bool yes
-
Execute the compiled application: After successful compilation, you can run the app directly from the Terminal:
./ClipboardApp
This will launch the application, and you should see a window with a text input field and two buttons: "Copy" and "Paste".
main.mm
: This is the entry point of the application. It sets up theNSApplication
instance and assigns anAppDelegate
to handle application lifecycle events.AppDelegate.h
: This is the header file for theAppDelegate
class. It declares the properties for the window, text field, and buttons, as well as the action method for the paste button.AppDelegate.mm
: This is the implementation file for theAppDelegate
class.applicationDidFinishLaunching:
: This method is called when the application has finished launching. It's where the UI elements (window, text field, buttons) are created, configured, and added to the window's content view.pasteText:
: This method is triggered when the "Paste" button is clicked. It accesses the system's general pasteboard (NSPasteboard
), retrieves the string content, and sets it as the value of the text field.applicationShouldTerminateAfterLastWindowClosed:
: This method ensures that the application quits when its last window is closed.
- Window: A simple application window titled "Clipboard App".
- Text Input: An
NSTextField
where you can type or paste text. - Paste Button: When clicked, it retrieves text from the system clipboard and displays it in the text input field.
- Copy Button: (Currently not implemented in the provided code snippet, but the button is visually present). To implement copy functionality, you would:
- Add an action method (e.g.,
copyText:
) toAppDelegate
. - In
copyText:
, get the string value fromself.textField
. - Get the general pasteboard.
- Clear the existing contents of the pasteboard.
- Declare the type of data to be copied (e.g.,
NSPasteboardTypeString
). - Set the string on the pasteboard.
- Connect this action method to the
copyButton
's target and action inapplicationDidFinishLaunching:
.
- Add an action method (e.g.,
This provides a basic foundation for a macOS clipboard utility.