Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 429009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:43:58+00:00 2026-05-12T19:43:58+00:00

We have the following snippet. OSStatus createErr = PasteboardCreate(kPasteboardClipboard, &m_pboard); if (createErr != noErr)

  • 0

We have the following snippet.

OSStatus createErr = PasteboardCreate(kPasteboardClipboard, &m_pboard);
if (createErr != noErr) {
    LOG((CLOG_DEBUG "failed to create clipboard reference: error %i" createErr));
}

This compiles fine, however, it fails to run when called from SSH. This is because there is no pasteboard available in the SSH terminal. However, the idea here is to share clipboards between computers.

When run from desktop terminal, this works just fine. But when run from SSH, PasteboardCreate returns -4960 (aka, coreFoundationUnknownErr). I assume that the only way around this issue is to run the application from within the same environment as the pasteboard, but is this possible?

  • Synergy+ issue 67
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:43:58+00:00Added an answer on May 12, 2026 at 7:43 pm

    Accessing the pasteboard directly looks to be a no-go. First, launchd won’t register the processes1 with the pasteboard server’s mach port. You’d first need find a way to get the pasteboard server’s mach port (mach_port_names?). Also, direct communication between user sessions is prohibited2, and other communication is limited. I’m not sure if your program will have the rights to connect to the pasteboard server.

    Here’s a first shot at an illustrative example on using Apple events to get & set the clipboard as a string. Error handling is minimal to nonexistent (I’m not certain how I feel about require_noerr). If you’re going to get/set clipboard data multiple times during a run, you can save the Apple events and, when copying to the clipboard, use AECreateDesc & AEPutParamDesc or (maybe) AEBuildParameters. AEVTBuilder might be of use.

    NSString* paste() {
        NSString *content;
    
        AppleEvent paste, reply = { typeNull, 0L };
        AEBuildError buildError = { typeNull, 0L };
        AEDesc clipDesc = { typeNull, 0L };
    
        OSErr err;
    
        err = AEBuildAppleEvent(kAEJons, kAEGetClipboard, 
                                typeApplicationBundleID, "com.apple.finder", strlen("com.apple.finder"), 
                                kAutoGenerateReturnID, kAnyTransactionID,
                                &paste, &buildError,
                                ""
            );
        require_noerr(err, paste_end);
        err = AESendMessage(&paste, &reply, kAEWaitReply, kAEDefaultTimeout);
        err = AEGetParamDesc(&reply, keyDirectObject, typeUTF8Text, &clipDesc);
        require_noerr(err, pastErr_getReply);
    
        Size dataSize = AEGetDescDataSize(&clipDesc);
        char* clipData = malloc(dataSize);
        if (clipData) {
            err = AEGetDescData(&clipDesc, clipData, dataSize);
            if (noErr == err) {
                content = [NSString stringWithCString:clipData encoding:NSUTF8StringEncoding];
            } else {}
            free(clipData);
        }
    
        AEDisposeDesc(&clipDesc);
    pastErr_getReply:
        AEDisposeDesc(&reply);
    pasteErr_sending:
        AEDisposeDesc(&paste);
    paste_end:
        return content;
    }
    
    OSStatus copy(NSString* clip) {
        AppleEvent copy, reply = { typeNull, 0L };
        AEBuildError buildError = { typeNull, 0L };
    
        OSErr err = AEBuildAppleEvent(kAEJons, kAESetClipboard, 
                                      typeApplicationBundleID, "com.apple.finder", strlen("com.apple.finder"), 
                                      kAutoGenerateReturnID, kAnyTransactionID,
                                      &copy, &buildError,
                                      "'----':utf8(@)",
                                      AEPARAMSTR([clip UTF8String])
                                      /*
                                        "'----':obj {form: enum(prop), want: type(@), seld: type(@), from: null()}"
                                        "data:utf8(@)",
                                        AEPARAM(typeUTF8Text),
                                        AEPARAM(pClipboard),
                                        AEPARAMSTR([clip UTF8String])
                                      */
            );
        if (aeBuildSyntaxNoErr != buildError.fError) {
            return err;
        }
        AESendMessage(&copy, &reply, kAENoReply, kAEDefaultTimeout);
        AEDisposeDesc(&reply);
        AEDisposeDesc(&copy);
        return noErr;
    }
    

    I’m leaving the Core Foundation approach above, but you’ll probably want to use NSAppleEventDescriptor to extract the clipboard contents from the Apple Event reply.

        err = AESendMessage(&paste, &reply, kAEWaitReply, kAEDefaultTimeout);
    require_noerr(err, pasteErr_sending);
        // nsReply takes ownership of reply
        NSAppleEventDescriptor *nsReply = [[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&reply];
        content = [[nsReply descriptorAtIndex:1] stringValue];
        [nsReply release];
    
    pasteErr_sending:
        AEDisposeDesc(&paste);
    paste_end:
        return content;
    }
    

    An NSAppleEventDescriptor is also easier to examine in a debugger than an AEDesc. To examine replies, you can also to set the AEDebugReceives environment variable when using osascript or Script Editor.app:

    AEDebugReceives=1 osascript -e 'tell application "Finder" to get the clipboard'
    

    References:

    1. “Configuring User Sessions”
    2. “Communicating Across Login Sessions”
    3. Mach Kernel Interface, especially:
      • mach_msg_header
      • mach_msg
    4. CFMessagePort Reference (mach port wrapper):
      • CFMessagePortCreateRemote
      • CFMessagePortSendRequest
    5. Apple Events Programming Guide
    6. Apple Event Manager Reference
    7. AEBuild*, AEPrint* and Friends
    8. AEBuildAppleEvent on CocoaDev
    9. Mac OS X Debugging Magic (for AEDebugSends and other AEDebug* environment variables)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code snippet to create NSSearchField programmatically mysearchField = [ [ NSSearchField
I have following code snippet: var reg = /^[0-9]$/; $('input[type=text]').keypress(function(){ console.log(reg.test(parseInt($(this).val()))); }); When I
I have following code snippet that i use to compile class at the run
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
I have the following snippet in one of my html pages : <div class=inputboximage>
I have the following snippet of code, changeTextArea is a TextArea object. changeTextArea.addKeyboardListener(new KeyboardListenerAdapter()
I have the following snippet where I would like to extract code between the
I have the following snippet of code that's generating the Use new keyword if
I have the following snippet from my code: switch ($extention) { case gif: $src
I have the following snippet of java code: File directoryToMoveTo = new File(file.getParent()+_TEMP); boolean

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.