Skip to content

Instantly share code, notes, and snippets.

@tobiasviehweger
Last active December 19, 2021 11:36
Show Gist options
  • Save tobiasviehweger/7a302b7179efb99082d8 to your computer and use it in GitHub Desktop.
Save tobiasviehweger/7a302b7179efb99082d8 to your computer and use it in GitHub Desktop.
Add image to shared iCloud photo stream programatically via COM on Windows
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace PhotoStreams
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 1)
return;
string imagePath = args[0];
string comment = args.Length > 1 ? args[1] : "";
GuidConverter gc = new GuidConverter();
Guid guid = (Guid)gc.ConvertFromString("3C5E2B20-B911-44E2-A2DD-9F05E7B5E775");
Type consoleType = Type.GetTypeFromCLSID(guid);
var photo = Activator.CreateInstance(consoleType) as PhotoStreams.IPhotoViewerHelper;
var list = photo.GetAlbumList();
string firstAlbumId = (string) list.GetValue(0);
photo.AddAssetsToAlbum(firstAlbumId, new string[] { imagePath }, new string[] { comment });
Marshal.ReleaseComObject(photo);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment