Best way to get a file path for presentation to the user

2015-12-18 Thread Graham Cox
Hi all,

I want to display a path to the user. I have a URL, I need to show the local 
file path that represents (it’s always a local file path), where the 
/Users// is replaced by ~/

Is there an easy, reliable way to do this, or do I have to do a string 
search/replace myself? Going the other way is trivial, I know, but I don’t see 
anything that gives me a displayable path given a URL.

—Graham



___

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: Best way to get a file path for presentation to the user

2015-12-18 Thread Graham Cox
Never mind, I just found it: stringByAbbreviatingWithTildeInPath


—Graham


> On 18 Dec 2015, at 8:24 PM, Graham Cox  wrote:
> 
> Hi all,
> 
> I want to display a path to the user. I have a URL, I need to show the local 
> file path that represents (it’s always a local file path), where the 
> /Users// is replaced by ~/
> 
> Is there an easy, reliable way to do this, or do I have to do a string 
> search/replace myself? Going the other way is trivial, I know, but I don’t 
> see anything that gives me a displayable path given a URL.
> 
> —Graham
> 
> 
> 
> ___
> 
> 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/graham.cox%40bigpond.com
> 
> This email sent to graham@bigpond.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: output string like a teleprinter (NSTextView)

2015-12-18 Thread sqwarqDev

> On 18 Dec 2015, at 06:34, Graham Cox  wrote:
> 
> If it happened accidentally it was most likely due to setting up a situation 
> that caused extreme low performance 

No, it wasn’t. 


> You could just gradually add characters from the original string to a 
> ‘display’ string using a timer and ask a standard layout manager/text view 
> etc. to re-lay and draw the display string.

I’m pretty sure I didn’t use a timer (see below).


> Using a custom NSLayoutManager is another way to go - it gives you the 
> opportunity to override almost any aspect of layout.


This sounds more likely. I was definitely playing around with NSLayoutManager 
at some point. I’ll look into that, but if anyone has any ideas how one would 
get the effect I’m after using NSLayoutManager I’d be grateful for the heads up.


> If you need less complex layout features, you could also do it using Core 
> Text.

Definitely definitely didn’t get into that!


> But just incremening a string and redrawing it in a textview is really by far 
> the simplest approach.
> 

Are you referring back to using a timer again? That might be one way to go. I’m 
pretty sure when I  “discovered” this effect, I was able to manipulate the 
timing (because at first I thought I’d use it, but I wanted it faster), but I’m 
pretty sure I didn’t know how to use timers in those days. Still, I’ll look 
again into this approach.

Thanks for all your insights, Graham. Much appreciated!


Best



Phil


___

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: output string like a teleprinter (NSTextView)

2015-12-18 Thread Graham Cox

> On 18 Dec 2015, at 8:37 PM, sqwarqDev  wrote:
> 
> I’m pretty sure I didn’t use a timer (see below).
> 


I wasn’t really trying to second-guess how you might have done this in the 
past; more, I was suggesting how you could do it without having “discovered” 
this effect previously. It definitely isn’t a standard behaviour of 
NSLayoutManager, and going that route seems a fairly complex solution to what 
is a pretty easy challenge. There’s nothing wrong with using a timer for this- 
it’s safe, easy, will cooperate with the rest of your app well and doesn’t even 
require any subclassing, though you might want to wrap the functionality up 
into a view or other class that you can give a string and the teleprinter 
effect just magically happens.

—Graham



___

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: CGContextClipToRects: invalid context 0x0.

2015-12-18 Thread Richard Charles
After researching I found answers to my questions.


> The first thing I noticed is that there are no debug symbols in Apple’s 
> frameworks. It that normal?

Apple’s frameworks do not have symbols.


> How do you debug something with no symbols?

Debugging a linked library without symbols is difficult (bordering on 
impossible).


With regards to this specific issue I submitted bug report 23955382.

--Richard Charles


___

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: Best way to get a file path for presentation to the user

2015-12-18 Thread Jens Alfke

> On Dec 18, 2015, at 1:24 AM, Graham Cox  wrote:
> 
> I want to display a path to the user. I have a URL, I need to show the local 
> file path that represents (it’s always a local file path), where the 
> /Users// is replaced by ~/

The best methods for this are in NSFileManager:

/* displayNameAtPath: returns an NSString suitable for presentation to the 
user. For directories which have localization information, this will return the 
appropriate localized string. This string is not suitable for passing to 
anything that must interact with the filesystem.
 */
- (NSString *)displayNameAtPath:(NSString *)path;

/* componentsToDisplayForPath: returns an NSArray of display names for the path 
provided. Localization will occur as in displayNameAtPath: above. This array 
cannot and should not be reassembled into an usable filesystem path for any 
kind of access.
 */
- (nullable NSArray *)componentsToDisplayForPath:(NSString *)path;

There are other transformations to the path for display besides “~”. For 
example, the user should never see “/Volumes”, or hidden suffixes like “.app”. 
And some names get completely localized for display — the “Downloads” directory 
looks like “Dvökhn¶r” in Elbonian, for example.

—Jens
___

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: Environment woes executing scripts from my OS X app

2015-12-18 Thread Clark Cox
If you know the environment variables you want to set, just use  /usr/bin/env. 
(that’s it’s raison d’être):

- Instead of executing:
path/to/script args

- Execute:
/usr/bin/env PYTHONPATH=… PYTHONHOME=...  path/to/script args

Or you can use posix_spawn to do the launching, which allows you to specify 
environment variables as well
Or, if posix_spawn isn’t available, you can fork() and use execle()
Or if execle() isn’t available, you can fork(), change the environment in your 
child process and then use plain-old exec()

> On Dec 16, 2015, at 14:29, Rick Mann  wrote:
> 
> Sorry, I didn't specify enough constraints in my original post.
> 
> - The code that calls the external scripts has to be cross-platform, and run 
> on linux as well as OS X. So, no NSTask.
> - I can modify the code that calls the scripts, and I can use OS X-only APIs 
> to set up a global environment (for processes launched by my app) if that 
> sort of thing is possible.
> - I don't want to make the user modify things like launchd config or /etc. 
> They can install required dependencies (like certain Python modules), but 
> that's about it. I'd love to find a way to package those in the app bundle, 
> too.
> 
> I'm thinking the best thing to do is pass in paths and an environment string 
> to be used in the system() call (e.g., invoke it as "export PYTHONPATH=...; 
> export PYTHONHOME=...; path/to/script args"). Maybe I can even leverage that 
> to let me put the requisite python modules in the app bundle...
> 
>> On Dec 16, 2015, at 11:07 , Paul Scott  wrote:
>> 
>> Sorry, I messed up the script. It should have been this:
>> 
>> set vars to { ¬
>>  {name:"ANT_HOME", value:"/usr/local/apache-ant-1.9.6"}, ¬
>>  {name:"CATALINA_HOME", 
>> value:"/Users/pscott/Projects/apache-tomcat-8.0.24"}, ¬
>>  {name:"LAUNCHD_SCRIPT", value:"/Users/pscott/bin/logon_as"}, ¬
>>  {done:true} ¬
>> }
>> repeat with i from 1 to (count of vars) - 1
>>  do shell script ¬
>>"/bin/launchctl setenv " & name of item i of vars & ¬
>>" " & value of item i of vars
>> end repeat
>> 
>> Paul
>> 
>>> By the way, you could also use this AppleScript, saved as an application, 
>>> and run automatically via the System Preferences -> Users & Groups -> 
>>> Current User -> Login Items configuration.
>>> 
>>> set vars to { ¬
>>>   { name:"ANT_HOME", value:"/usr/local/apache-ant-1.9.6" }, ¬
>>>   { name:"CATALINA_HOME", value:”/usr/local/apache-tomcat-8.0.24" }, ¬
>>>   { done: true } ¬
>>> }
>>> repeat with i from 1 to count of vars - 1
>>>  do shell script "/bin/launchctl " ¬
>>> & name of item i of vars & " " ¬
>>> & value of item 1 of vars
>>> end repeat
>>> 
>>> That is much easier to set up, but has the disadvantage of bouncing the 
>>> application icon in the Dock momentarily at login. The launchd mechanism is 
>>> silent, and seems to complete a tad bit sooner.
>>> 
>>> Paul
>>> 
 On Dec 16, 2015, at 15:47, Rick Mann  wrote:
 
> I'm working on an OS X app that unfortunately has to call a series of 
> bash and python scripts for part of the processing it does. I was able to 
> include the scripts in my app's bundle, and invoke them there, but the 
> environment is different when launched via my app than when launched on 
> the command line. How can I best control the environment used when 
> executing external scripts?
> 
> -- 
> Rick Mann
> rm...@latencyzero.com
 
 
 If you want to have specific environment variables set for all apps 
 launched regardless of how they were launched, you can use the launchd 
 mechanism, which is compatible with all the latest Mac OS X releases.
 
 You can put this file in ~/Library/LaunchAgents/local.launchdrc.plist 
 
 
 >>> "http://www.apple.com/DTDs/PropertyList-1.0.dtd";>
 
 
  Label
  local.launchdrc
  Disabled
  
  RunAtLoad
  
  ProcessType
  Background
  ProgramArguments
  
  /Users/yourusername/.launchdrc
  
  StandardErrorPath
  /dev/null
  StandardOutPath
  /dev/null
 
 
 
 Then, create ~/.launchdrc (chmod 755) that looks something like this:
 
 #!/bin/sh
 launchctl setenv ANT_HOME "/usr/local/apache-ant-1.9.6"
 launchctl setenv CATALINA_HOME “/usr/local/apache-tomcat-8.0.24”
 
 Where each environment variable you want available to all launched apps is 
 listed. Add variables as needed. This will set up an environment for the 
 user at login time that will get picked up by all launched apps, whether 
 run from the command line or launched via Finder.
 
 This replaces the old ~/.MacOSX mechanism where you could set environment 
 variables at login.
>>> 
> 
> 
> -- 
> Rick Mann
> rm...@latencyzero.com 
> 
> 
> 
> ___
> 
> Cocoa-dev mail

Re: Best way to get a file path for presentation to the user

2015-12-18 Thread Ken Thomases
On Dec 18, 2015, at 12:23 PM, Jens Alfke  wrote:
> 
>> On Dec 18, 2015, at 1:24 AM, Graham Cox  wrote:
>> 
>> I want to display a path to the user. I have a URL, I need to show the local 
>> file path that represents (it’s always a local file path), where the 
>> /Users// is replaced by ~/
> 
> The best methods for this are in NSFileManager:

> - (NSString *)displayNameAtPath:(NSString *)path;

> - (nullable NSArray *)componentsToDisplayForPath:(NSString *)path;
> 
> There are other transformations to the path for display besides “~”. For 
> example, the user should never see “/Volumes”, or hidden suffixes like 
> “.app”. And some names get completely localized for display — the “Downloads” 
> directory looks like “Dvökhn¶r” in Elbonian, for example.

And in a UI, it may be better to use an NSPathControl than to display a path as 
text.

Regards,
Ken


___

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: CGContextClipToRects: invalid context 0x0.

2015-12-18 Thread Quincey Morris
On Dec 18, 2015, at 08:59 , Richard Charles  wrote:
> 
> Apple’s frameworks do not have symbols.

IIRC several OS X versions ago, Apple use to release versions of the system 
frameworks that included symbols, but this wasn’t very useful because they came 
out so much later than the OS itself. I don’t know if they’ve done that for 
recent versions. You could look in the developer downloads to find out.

Regarding the original problem (since no one who knew anything jumped in), I 
think I’ve seen this complained of occasionally during the last couple of 
years. Sometimes it indicates that internal Apple code wasn’t changed when API 
was deprecated. It works fine, but as OS versions march on the complaints from 
the deprecated API get more insistent.

So it may not be anything to do with your code. The best thing to do is file a 
radar and let them tell you not to worry about it.



___

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: CGContextClipToRects: invalid context 0x0.

2015-12-18 Thread Uli Kusterer
On 18 Dec 2015, at 17:59, Richard Charles  wrote:
> Debugging a linked library without symbols is difficult (bordering on 
> impossible).

 It's not easy, but far from impossible. If you can read assembly, you can 
usually figure out quite a lot. The debugger will disassemble stack frames for 
you when you step into them. It would be a little easier for Objective-C code, 
where all method names are registered publicly, as are class names and a good 
part of each object's layout.

It helps to familiarize oneself with LLDB's commands. Particularly what 
registers 64-bit apps use to store parameters and how to print them from inside 
a method call, and how the 'po' command works for printing objects.

But for complaints about an invalid context, it sometimes helps to verify that 
any API you use from the library this error comes from is documented to accept 
NULL where you pass it NULL. And in this case I'd also print the current 
CGContext before any calls you make, and ensure that you save and restore your 
context before and after any calls where you change it, especially if you 
create your own contexts. And ensure that you retain any contexts that you're 
keeping around across calls, and verifying that your window is visible and not 
deferred if you try to draw in it. (This is all assuming you're not making a 
basic mistake like calling drawRect: directly or (even indirectly) requesting 
redraws from inside drawRect:

If none of this helps, a common occurrence of weird behaviour like this is also 
sometimes screwing up internal state by using thread-safe API that is not 
documented to support being used from more than one thread at once, or API 
that's not safe to use from non-main threads at all, from several threads. Any 
if that ring a bell?

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://stacksmith.org





___

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: Best way to get a file path for presentation to the user

2015-12-18 Thread Uli Kusterer
On 18 Dec 2015, at 21:33, Ken Thomases  wrote:
> On Dec 18, 2015, at 12:23 PM, Jens Alfke  wrote:
>> 
>>> On Dec 18, 2015, at 1:24 AM, Graham Cox  wrote:
>>> 
>>> I want to display a path to the user. I have a URL, I need to show the 
>>> local file path that represents (it’s always a local file path), where the 
>>> /Users// is replaced by ~/
>> 
>> The best methods for this are in NSFileManager:
> 
>> - (NSString *)displayNameAtPath:(NSString *)path;
> 
>> - (nullable NSArray *)componentsToDisplayForPath:(NSString 
>> *)path;
>> 
>> There are other transformations to the path for display besides “~”. For 
>> example, the user should never see “/Volumes”, or hidden suffixes like 
>> “.app”. And some names get completely localized for display — the 
>> “Downloads” directory looks like “Dvökhn¶r” in Elbonian, for example.
> 
> And in a UI, it may be better to use an NSPathControl than to display a path 
> as text.

Definitely recommend using an NSPathControl and to avoid displaying a path at 
all. Most users don't understand file paths. Also keep in mind that display 
names are HFS-style names that may contain slashes, so using a slash as a path 
separator with those can lead to wrong display.

Check out what the "Open recent" submenu does with file names for a good idea 
to follow if you can't use a path control. Particularly how it distinguishes 
between two files with the same name in different locations.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://stacksmith.org





___

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