Friday, December 15, 2017

#1 2009-10-28 12:39:11 pm

tellboy
Member
Registered: 2005-06-23
Posts: 152

Passing by reference

Hi all,

Does anyone know how to implement this line of Cocoa in ASOC?

Applescript:

[[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&dir];

Please note it is the  &dir I am interested in. How do you implement this in ASOC.

I tried " a reference to" without success.

Thanks

--Terry

Offline

 

#2 2009-10-28 04:51:29 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: Passing by reference

FWIW, I've had no luck doing it either.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2009-10-30 01:10:09 pm

SuperMacGuy
Member
From:: Amish Country, Lancaster, PA
Registered: 2004-06-23
Posts: 416
Website

Re: Passing by reference

The &dir is the memory address of a variable. I think I see where you got this from (in XCode documentation), but you don't have to use &dir,  you can just put a regular boolean.

Here's the actual declaration:
- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory

could you do:
[[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:YES];
?


Scripts for InDesign: http://chris.paveglio.com
ASOC & Cocoa, specializing in InDesign, Photoshop, Ai, FileMaker

Offline

 

#4 2009-10-30 01:24:43 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Passing by reference

the expression
[code](BOOL *)isDirectory[/code]
is no regular boolean, *isDirectory is a pointer to a memory location, which will be returned with the address operator &

The "regular" boolean to be treated as input would be
[code](BOOL )isDirectory[/code]


regards

Stefan

Offline

 

#5 2009-10-30 01:47:42 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Passing by reference

PS: this might be an alternative

[code]NSString *myDir = @"/Library/Preferences";
    BOOL isDir = [[[NSFileManager defaultManager] attributesOfItemAtPath:myDir error:NULL] objectForKey:NSFileType] == NSFileTypeDirectory;
    NSLog(@"%i", isDir); // 1[/code]


regards

Stefan

Offline

 

#6 2009-10-31 07:07:45 am

tellboy
Member
Registered: 2005-06-23
Posts: 152

Re: Passing by reference

Thanks StefanK this seems to work.

For others I have prepared a small example script which logs the info returned. Please see the console.

This needs to be attached to a button to try it.

Applescript:

   on checkDir_(sender)
       set tPanel to NSOpenPanel's openPanel()
       tPanel's setCanChooseDirectories_(true)
       tPanel's setCanChooseFiles_(false)
       tPanel's setAllowsMultipleSelection_(false)
       
       tPanel's setAllowedFileTypes_(missing value)
       
       tPanel's runModal()
       
       set tMyDir to tPanel's filenames()'s objectAtIndex_(0)
       log tMyDir
       
       set isDir to false
       
       set tDefaultManager to NSFileManager's defaultManager()
       set tAttribs to tDefaultManager's attributesOfItemAtPath_error_(tMyDir, missing value)
       log tAttribs
       
       set tFileType to tAttribs's objectForKey_("NSFileType") as string
       log tFileType
       
       if tFileType = "NSFileTypeDirectory" then
           set isDir to true
           beep
       end if
   end checkDir_

All the best

--Terry

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)