AppleScript-> Get contact photo-> NSImage

I hope that red_menace or ASObjC another expert will see this.

In collaboration with AppleScript, I have:

tell application "Contacts"
   set theImage to image of somePerson
end tell

You are on the right track, but the Contacts.app image data is not in a format that like cocoa (even if the .sdef said NSData, it does not seem make it cross the bridge).  I looked around a bit and have not found a direct conversion, but there are two ways to do it.  First of all, you can use StandardAdditions to write the image AppleScript in a file and then use NSImage initWithContentsOfFile: method to read it back in.  If you're not wanting to use a file to perform the conversion, you can also perform the conversion of data by program, although it is more than a run around.

To do your own conversion, you need get the data of the AppleScript into another container (for example, a string), and then convert it to a cocoa NSData object.  You cannot force the data directly in a string, to do an end run around of AppleScript to do.  One way is to use and the shell script osascript (which returns the text), another is to use a try statement to force an error, since even if AppleScript will not force the data to a string, it will tell you what it is in a chain of error message (?):

        tell application id "com.apple.AddressBook" to set theImage to image of my card
        try
                theImage as string -- force an error
        on error errMsg -- strip the terms and chevrons from the error message
                set here to (offset of "«" in errMsg) + 10
                set there to (offset of "»" in errMsg) - 1
                set imageString to text here thru there of errMsg
        end try
        log imageString -- note that the string is pretty long, even with a small image

Tags: iOS Developer

Similar Questions

  • Me and my dad is from the same Apple ID and I want to set up his own, but how it will get all his contacts, photos etc from my Apple ID? Or he will lose all? or I could keep them saved for him and send more via an application any?

    Me and my dad is from the same Apple ID and I want to set up his own, but how it will get all his contacts, photos etc from my Apple ID? Or he will lose all? or I could keep them saved for him and send more via an application any? I don't know how to resolve this issue, if someone could point me in the right direction.

    Have him create a id Apple here- create and start using a Apple - Apple Support ID, and then both you can create an album-photo sharing Photo Sharing - Apple Support iCloud

  • Contact photos are compressed/low quality

    I love my bike 360. But sometimes, when I get a message from den contact photo that appears as the background sounds, well, terrible. Ive tried to change the contact's photo on my phone at a better resolution photo, but it always looks bad. Its a nice watch and it's a shame the photos seem so compressed. I know that its possible to get beautiful surfaces of contact because of the demo seen in videos. In addition, Album art seems good too. Someone knows how to optimize photos contact on my phone so that they look good on the watch? Thank you.

    I've contacted the developers Android wear and got a little more information.

    It turns out that it is a problem with the application Google Hangouts is hard-coded. For those that care here is the answer I received from Wayne Piekarski:

    "The app Hangouts was previously using setLargeIcon since it is what the Notification API provided previously. Now that they have updated so that it uses setBackground() to Android, and a future update will push this. »

    Thus, it seems that we just have to wait and Hangouts team will take care of that with an update. Maybe it's something to talk to other developers if you notice the same error.

  • Contact photos not appearing is not in the list of text messages

    Recently, I deleted all my contacts on my droid x in order to refresh my facebook contact photos (I do this since we all know the phone doesn't seem to update the photos themselves, as it should).  After importing my contacts back on my phone and set up my facebook account, once again, I've linked contacts that does not automatically link and now everything seems good.

    Here's where I noticed the problem.  Now pictures of my contacts are not at all in my application of message text (SMS GO).  I checked the application of the default text and they appear in there, but not in GO SMS. So I tried to uninstall GO SMS, wiping the cache on the phone and reinstalling GO SMS, but the images still do not appear.  It just shows the default avatar next to the name.

    Someone at - it suggestions that I could try to get the images to load into GO SMS?

    It's a very good theory.  To test this, you could install an application called SyncMyPix that queries your Facebook account to take photos and make them peak of gmail.  If your text app, then updates that your theory is right.  I hope this helps.

  • InputStream and Contact.Photo

    I use the 4.6.0 9000 Simulator. Here is the code I use:

    static final class GetPhoto extends Thread {
                public GetPhoto(){}
    
                public void run(){
                    StreamConnection s;
                    String person = "http://somewebsite";
                    try{
                        s = (StreamConnection)Connector.open(person + (String)cvals.get("CNUM"), Connector.READ, true);
                        HttpConnection httpConn = (HttpConnection)s;
                        int status = httpConn.getResponseCode();
                        if (status == HttpConnection.HTTP_OK){
                            InputStream input = s.openInputStream();
                            byte[] data2 = new byte[input.available()];
                            input.read(data2, 0, input.available());
                            byte[] photoEncoded = Base64OutputStream.encode(data2, 0, data2.length, false, false);
                            if (c.countValues(Contact.PHOTO) > 0) {
                                c.setBinary(Contact.PHOTO, 0, PIMItem.ATTR_NONE, photoEncoded,
                                    0, data2.length);
                            } else {
                                c.addBinary(Contact.PHOTO, PIMItem.ATTR_NONE, photoEncoded,
                                    0, data2.length);
                            }
    
                            // if record is modified, commit
                            if (c.isModified()){
                                try{
                                    c.commit();
                                } catch (PIMException e){
                                    errMessage = "Error in getPhoto commit. Error:" + e.getMessage();
                                    errCnt++;
                                }
                            }
                            s.close();
                        }
                    } catch (IOException e){
                        errMessage = "Error in getPhoto. Error:" + e.getMessage();
                        errCnt++;
                    }
                    photoCont = true;
                }
            }
    

    I used this code to upload photos and it works fine until I came across one that seems to be bigger than the norm. I have tested on one that works and the gross size returned was 7965 bytes and coded was 10620 bytes. When I try that largest is raw still 7965 but fails after that. It only returns the part of the photo and the other part is blurred.

    Yes, there is a lot that is returned when you use InputStream.available () and I don't have to put it in some kind of loop to get the entire photo? If this is not the case, why then is it is blurred. I used Java on the desktop to get the photo from the same web site and it works fine so I know that the photo is not damaged. I use different methods of retruning photography on the side of the desktop.

    Thank you.

    byte[] chunk = new byte[4 * 1024];
    ByteArrayOutputStream read2Buf = new ByteArrayOutputStream();
    int chunkLength;
    while ((chunkLength = input.read(chunk)) != -1) {
      read2Buf.write(chunk, 0, chunkLength);
    }
    byte[] read2 = read2Buf.toByteArray(); 
    

    You must run a loop on InputStream.read to read the entire stream (see contract InputStream.read in J2SE/J2ME Javadocs).

    OR specific BB:

    byte[] read2 = IOUtilities.stream2Bytes(input);
    
  • I can't seem to get contacts or calendars to sync

    So, I recently bought a mac book pro to a friend.  I also own an iPhone 6.  I wonder why I can't get contacts or calendars to synchronize between the two.  I am instructor and I well well conferences also Webcast online that I get calls on my phone.  Is there a way to get these things to synchronize or I'm just a fool.  IM currently paying for storage iCloud and I have both products on the same iTunes / apple ID.

    < re-titled by host >

    "a friend bought a mac book pro.

    The problem may be due to the fact that the Mac is always associated with the, 'friends', Apple ID.

    Evolution of the property of a Mac of opportunity

  • Can not get the photo stream to show in pictures

    Despite rooting in the preferences I can't seem to be able to get my photo stream will appear in the pictures. Someone has an idea of what I might have missed?

    TT2

    As you mentioned not directly - do you have activated my PhotoStream also in iCloud Photos for Mac preferences?

    Photos > Preferences > iCloud:

    My Photo stream will only show in the photo library, which has been enabled in your system in pictures photo library > Preferences > General.

    This option should be grayed out to show that it is enabled.

  • How to quickly get 100 + photos from iPhone in pictures on iMac with the download speed very low broadband?

    Hi all

    I have an iPhone 6 Plus running iOS 9.3.1 and a retina iMac running OSX El Capitan 10.1.4.  I use iCloud photo library and I like the idea of having all the pictures synced across all devices.  This works well for one or two odd photos I take here and there.

    I have just been on vacation and taken 100 + photos with my iPhone and want to create an album of photo printed on my iMac, but the problem I am facing is that it takes so long to get the pictures on pictures on my iMac.

    My download speed high speed is very low - on 0.3Mbit / s, so the photos are always download to iCloud from my iPhone now, and I guess it will be another day or two to complete.

    Is it possible to get the photos from my iPhone to the iMac more quickly without creating duplicates or spoil my library?

    It's so frustrating to have to wait 5 days after her return from vacation before you can start making a photo album.

    Thanks for any help,

    Kind regards

    Ben

    You can connect the phone with USB and import or use iTunes sync or Capture of Image - this can cause a problem with duplicates

    And of course, you can stop by a store StarBucks, Apple (or other WiFi hotspot with good service) and complete quickly

    LN

  • I opened MY Facebook id and I get my photos of friends from my mistake I don't know who im key press + photos going to hide how I is new im trying to come back, but I never see still photos im click on the image, but im can not show me

    I opened MY Facebook id and I get my photos of friends from my mistake I don't know who im key press + photos going to hide how I is new im trying to come back, but I never see still photos im click on the image, but im can not show me

    This has happened

    Don't know how many times

    is 2 days befor

    It is possible that you clicked the 'Block Images' item in the context menu by attempting to save an image.
    Check the image exceptions: Tools > Options > content: Load Images: Exceptions - see the web content, pop-ups, fonts and language settings

    A way to see what images are blocked is to click on the favicon (Site ID icon) on the left side of the address bar.
    Click on the "More information" button opens the Security tab of the "Page Info" window (also accessible via "tools > Page Info").
    Go to the tab Media of this "Page Info" window.
    Select the first image and scroll though the list with the arrow pointing downwards.
    If an image in the list is grayed out and there is a check mark in the box "block Images of..." and remove this mark to unlock the images from this area.

    See also the problems that cause to not show images and http://kb.mozillazine.org/Images_or_animations_do_not_load

  • I can't seem to get contact 3D to work

    I can't get contact 3D to work.  What I need to change settings or it should work automatically?

    Go to settings | General | Accessibility | Tactile 3D

    Make sure it is on, and then you can set the sensitivity and test it.

  • When I click on the icon of the music I get a * photo

    When I click on the icon of the music I get a * photo of a baby in front of a nice brick wall. Nothing else. Thanks for this Apple.

    #SteveIsDead

    Double click on the home button and drag the application to the top music. Then hold down the sleep/wake and the "home" button until the Apple logo appears. When you open the music app upward, you should see an option "go to my music" - AJ

  • Contact photos not no projection in iMessage iPhone 6s

    I know that this issue is already several times. But no solid answers. Contact photos does not and iMessage. Parameters are the standard not zoom I tried everything everyone has tried. Is this a problem with Apple, or is there another solution. Nothing is clear at this point.

    To display pictures of contacts in messages, you must go to settings > Messages > then turn on "show the Photos of Contact."

  • The contact photo sync if contact has Facebook account

    (1) the contact photo will not sync to Google on refuse if the contact has a Fcaebook account, even if there is no picture associated Facebook account. The generic image appears slightly larger and brighter that the generic image on contacts without a Facebook account. Is there a work around?

    (2) is there a way to stop denying it sync with Facebook contacts, far delete the account?


  • Contact photos...

    My Exchange Server Contacts sync properly, parasol that demonstrate any of the contacts photos. Does anyone else have this problem?

    Your contacts in Outlook are different, then the address list global (LAG) associated with Microsoft Exchange. Your company provides photos contacts (usually not), what is your personal contacts, are you worried?

  • Z2: Contact Photos don't show up when you call

    After the sync of my new phone of z2 xperia with gmail, I see the contact photos in 'contacts' However, when I call someone, the picture does not show on the screen, it shows just the credits of 'head '.

    they are NOT sim or phone contacts, I changed all the contacts of the SIM to gmail contacts just for that purpose.

    why I don't see the contact pictures?

    EDIT: it seems to be a problem for some, but not all, contacts

    Open the directory > menu > settings > filter > uncheck all options > restart your phone > access to the filter, and then select only Gmail

Maybe you are looking for

  • No digital noise

    I recently bought a new computer from desktop HPE-300z, personalized with a card his Creative Sound Blaster X - Fi Xtreme Audio (Windows 7 Home Premium OS).  I tried to reach my old Boston Acoustics speakers 'Digital Media Center' system but not soun

  • Windows 7 - offered several times the same update

    Hello I'm having a problem with my machine to lock up when I try to run programs. There seems to be no problem with my hardware - both my HDD and RAM have passed the tests. However, I noticed that windows 7 guard trying to install the same updates. I

  • Error code: 0x8007001f and six critical updates failed to install.

    Original title: I have six critical updates which will not refresh error. I have six critical updates which does not update error 0x8007001f code anyone with an answer

  • XP SP3 no sound after reinstalling the operating system

    Hello I have re-installed the SP3 of XP on my Toshiba laptop and it has no sound after that. You may have installed the operating system in "secret" mode and so there is no sound. I checked the audio settings are that all settings are correct. Is it

  • Disable alerts for specific volume?

    One of my servers monitored with Foglight SQL has a volume that is only used for TempDB. The size configured for TempDB use about 97% of the storage on the volume. Thus the agent host continuously generates an alert. My question is what is the best a