Re: Proper way to retrieve the NSScreenNumber in a screen saver ?

2022-12-11 Thread Steve Mills via Cocoa-dev
I mentioned somewhere in one of my replies that you know when it’s being run in 
the System Prefs preview because isPreview is passed to the main entry point.

Steve via iPad

> On Dec 11, 2022, at 14:56, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> Thanks again for the responses. And sorry for following up so much later.
> (a bit of context is recapped below)
> 
> First of all, thanks for the hint to viewDidMoveToWindow.
> 
> So, currently , I do this in my viewDidMoveToWindow:
> 
> 
> - (void) viewDidMoveToWindow
> {
>window_ = [self window];
>NSUInteger idx_of_screen = [NSScreen.screens indexOfObject: 
> window_.screen];
>displayID_ = [NSNumber numberWithUnsignedLong: idx_of_screen ];
> 
> 
> On my Mac this runs fine, and I get a proper idx_of_screen/displayID_;
> 
> However, one of my users sent me a log file, which shows that on his Mac, 
> [self window] is non-null, but indexOfObject: returns NSNotFound, in the case 
> where my screensaver is running in the preview of System Preferences.
> (One difference between the systems is that I am still using macOS 12, while 
> he is using macOS 13.)
> 
> I guess, there is not much I can do about it, except find some kind of 
> work-around for those cases, where this happens. Right?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to convert path through container into standard form?

2022-12-11 Thread Sandor Szatmari via Cocoa-dev
I was thinking that’d break sandbox encapsulation.  But I guess what really 
matters is what you get when you do the reverse and expand the tilde?

> 
> On Dec 11, 2022, at 17:58, Ben Kennedy via Cocoa-dev 
>  wrote:
> 
> 
> 
>> On 11 Dec 2022, at 12:51 pm, Mike Abdullah via Cocoa-dev 
>>  wrote:
>> 
>> Have you tried -URLByResolvingSymlinksInPath? As far as I’m aware, the 
>> Pictures entry inside your container is a symlink to the real thing, so 
>> assuming you have appropriate entitlements, should be possible to resolve it.
> 
> 
> Indeed, it seems to work in a Swift REPL. Issuing...
> 
> (URL(fileURLWithPath: 
> "/Users/ben/Library/Containers/com.apple.ScreenSaver.Engine/Data/Pictures").resolvingSymlinksInPath().path
>  as NSString).abbreviatingWithTildeInPath
> 
> ...yeilds "~/Pictures".
> 
> -ben
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/admin.szatmari.net%40gmail.com
> 
> This email sent to admin.szatmari@gmail.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to convert path through container into standard form?

2022-12-11 Thread Ben Kennedy via Cocoa-dev


> On 11 Dec 2022, at 12:51 pm, Mike Abdullah via Cocoa-dev 
>  wrote:
> 
> Have you tried -URLByResolvingSymlinksInPath? As far as I’m aware, the 
> Pictures entry inside your container is a symlink to the real thing, so 
> assuming you have appropriate entitlements, should be possible to resolve it.


Indeed, it seems to work in a Swift REPL. Issuing...

(URL(fileURLWithPath: 
"/Users/ben/Library/Containers/com.apple.ScreenSaver.Engine/Data/Pictures").resolvingSymlinksInPath().path
 as NSString).abbreviatingWithTildeInPath

...yeilds "~/Pictures".

-ben

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to convert path through container into standard form?

2022-12-11 Thread Sandor Szatmari via Cocoa-dev
Looking back, I guess you’d bump up against the sandbox with this… 

> 
> On Dec 11, 2022, at 16:21, Sandor Szatmari  
> wrote:
> 
> -stringByAbbreviatingWithTildeInPath
> 
> First page in google results
> 
>> On Dec 11, 2022, at 15:06, Gabriel Zachmann via Cocoa-dev 
>>  wrote:
>> 
>> 
>> I have an NSURL * pictures_path;
>> 
>> By default, this is set to 
>> 
>> pictures_path = [ [NSFileManager defaultManager] URLForDirectory: 
>> NSPicturesDirectory
>>inDomain: NSUserDomainMask
>>   appropriateForURL: nil create: NO error: 
>> ];
>> 
>> This works fine.
>> 
>> Occasionally, I am printing a log message, like so:
>> 
>> mesg = [[NSMutableString alloc] initWithString: [mainDirectoryLocation_ 
>> pictures_path] ]; 
>> 
>> and then output that to whatever channel is active (screen or log file).
>> 
>> Now, in cases where pictures_path is still set to the default, 
>> the users sees some thing like:
>> 
>> /Users//Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Pictures
>> 
>> which is confusing to the user (and takes up a lot of space).
>> 
>> How can I convert this back to the more human-readable /Users/xx/Pictures  
>> or ~/Pictures ?
>> 
>> I have checked NSURL's doc, but couldn't find a method to convert the path.
>> 
>> 
>> Hints will be appreciated.
>> Best, Gabriel.
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/admin.szatmari.net%40gmail.com
>> 
>> This email sent to admin.szatmari@gmail.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to convert path through container into standard form?

2022-12-11 Thread Sandor Szatmari via Cocoa-dev
-stringByAbbreviatingWithTildeInPath

First page in google results

> On Dec 11, 2022, at 15:06, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> 
> I have an NSURL * pictures_path;
> 
> By default, this is set to 
> 
>  pictures_path = [ [NSFileManager defaultManager] URLForDirectory: 
> NSPicturesDirectory
> inDomain: NSUserDomainMask
>appropriateForURL: nil create: NO error: 
> ];
> 
> This works fine.
> 
> Occasionally, I am printing a log message, like so:
> 
>  mesg = [[NSMutableString alloc] initWithString: [mainDirectoryLocation_ 
> pictures_path] ]; 
> 
> and then output that to whatever channel is active (screen or log file).
> 
> Now, in cases where pictures_path is still set to the default, 
> the users sees some thing like:
> 
>  
> /Users//Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Pictures
> 
> which is confusing to the user (and takes up a lot of space).
> 
> How can I convert this back to the more human-readable /Users/xx/Pictures  or 
> ~/Pictures ?
> 
> I have checked NSURL's doc, but couldn't find a method to convert the path.
> 
> 
> Hints will be appreciated.
> Best, Gabriel.
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/admin.szatmari.net%40gmail.com
> 
> This email sent to admin.szatmari@gmail.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Proper way to retrieve the NSScreenNumber in a screen saver ?

2022-12-11 Thread Gabriel Zachmann via Cocoa-dev
Thanks again for the responses. And sorry for following up so much later.
(a bit of context is recapped below)

First of all, thanks for the hint to viewDidMoveToWindow.

So, currently , I do this in my viewDidMoveToWindow:


- (void) viewDidMoveToWindow
{
window_ = [self window];
NSUInteger idx_of_screen = [NSScreen.screens indexOfObject: window_.screen];
displayID_ = [NSNumber numberWithUnsignedLong: idx_of_screen ];


On my Mac this runs fine, and I get a proper idx_of_screen/displayID_;

However, one of my users sent me a log file, which shows that on his Mac, [self 
window] is non-null, but indexOfObject: returns NSNotFound, in the case where 
my screensaver is running in the preview of System Preferences.
(One difference between the systems is that I am still using macOS 12, while he 
is using macOS 13.)

I guess, there is not much I can do about it, except find some kind of 
work-around for those cases, where this happens. Right?


Best regards, Gabriel



>
>> On Nov 17, 2022, at 16:11, Gabriel Zachmann via Cocoa-dev 
>>  wrote:
>>
>> ?Thanks a lot for your quick responses!
>>
>> I would like to understand what you are saying and what is going on, so 
>> please bear with me.
>>
>> So, Steve, if I understand correctly, you suggest to write:
>>
>> - (void) viewWillMoveToWindow: (NSWindow *) newWindow
>> {
>>   unsigned long my_screen = [NSScreen.screens indexOfObject: [newWindow 
>> screen]];
>>   displayID_ = [[ [NSScreen.screens[my_screen] deviceDescription] 
>> objectForKey: @"NSScreenNumber"];
>> ...
>> }
>
> No, I didn?t suggest that. I suggested just using the screen?s index via 
> indexOfObject as the screen number. No need to dive into the device 
> description. It?s exactly what I do my screensaver.
>
> I see in my code I only access the window.screen in viewDidMoveToWindow, not 
> viewWillMoveToWindow. Perhaps the window has not yet been assigned to a 
> screen in WillMove.
>



smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to convert path through container into standard form?

2022-12-11 Thread Mike Abdullah via Cocoa-dev
Have you tried -URLByResolvingSymlinksInPath? As far as I’m aware, the Pictures 
entry inside your container is a symlink to the real thing, so assuming you 
have appropriate entitlements, should be possible to resolve it.

Mike.

> On 11 Dec 2022, at 10:56, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> 
> I have an NSURL * pictures_path;
> 
> By default, this is set to 
> 
>  pictures_path = [ [NSFileManager defaultManager] URLForDirectory: 
> NSPicturesDirectory
> inDomain: NSUserDomainMask
>appropriateForURL: nil create: NO error: 
> ];
> 
> This works fine.
> 
> Occasionally, I am printing a log message, like so:
> 
>  mesg = [[NSMutableString alloc] initWithString: [mainDirectoryLocation_ 
> pictures_path] ]; 
> 
> and then output that to whatever channel is active (screen or log file).
> 
> Now, in cases where pictures_path is still set to the default, 
> the users sees some thing like:
> 
>  
> /Users//Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Pictures
> 
> which is confusing to the user (and takes up a lot of space).
> 
> How can I convert this back to the more human-readable /Users/xx/Pictures  or 
> ~/Pictures ?
> 
> I have checked NSURL's doc, but couldn't find a method to convert the path.
> 
> 
> Hints will be appreciated.
> Best, Gabriel.
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/mabdullah%40karelia.com
> 
> This email sent to mabdul...@karelia.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


How to convert path through container into standard form?

2022-12-11 Thread Gabriel Zachmann via Cocoa-dev

I have an NSURL * pictures_path;

By default, this is set to

  pictures_path = [ [NSFileManager defaultManager] URLForDirectory: 
NSPicturesDirectory
 inDomain: NSUserDomainMask
appropriateForURL: nil create: NO error: 
];

This works fine.

Occasionally, I am printing a log message, like so:

  mesg = [[NSMutableString alloc] initWithString: [mainDirectoryLocation_ 
pictures_path] ];

and then output that to whatever channel is active (screen or log file).

Now, in cases where pictures_path is still set to the default,
the users sees some thing like:

  
/Users//Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Pictures

which is confusing to the user (and takes up a lot of space).

How can I convert this back to the more human-readable /Users/xx/Pictures  or 
~/Pictures ?

I have checked NSURL's doc, but couldn't find a method to convert the path.


Hints will be appreciated.
Best, Gabriel.



smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com