Re: SaveLink: opening a .url file selected from the FileViewer of GWorkspace: Fixed
Patrick CARDONA <[email protected]> Sun, 01 Mar 2026 18:24:21 +0100
| Newsgroups | gmane.comp.lib.gnustep.general |
|---|---|
| Message-ID | <8a888d39b8817b575d65ba07c2db94c8@pi500> |
Hello All,
I finally fixed the path issue using the following code with
'lastObject' to handle the different arguments count:
> NSArray *arguments = [[NSProcessInfo processInfo] arguments];
> // Check if there are any arguments passed
> if ([arguments count] > 1) {
> NSString *filePath = [arguments lastObject]; // The first
> argument is
> the file path
> [self openWithPath: filePath];
> }
>
On 2026-02-28 23:34:24 +0100 Patrick CARDONA <[email protected]>
wrote:
> Hello All,
>
> SaveLink app is not yet complete.
>
> The 'open' method called from the command menu is working.
> Also I improved the code using more specific Path handle methods:
>> NSString *nameLink = [[openPath lastPathComponent]
>> stringByDeletingPathExtension];
>
> But I must handle now the case when a '.url' file is selected and
> opened by
> SaveLink from the 'open-With' menu of GWorkspace to be edited.
>
> So:
> - I declared a new method: '(void) openWithPath: (NSString *)
> pathFile';
> - I tried to call 'openWithPath:' from 'awakeFromNib' like this:
>
>> NSLog(@"Enter...");
>> NSArray *arguments = [[NSProcessInfo processInfo] arguments];
>
>> // Check if there are any arguments passed
>> if ([arguments count] > 1) {
>> NSString *filePath = [arguments objectAtIndex:1];
>
>> NSLog(@"File to open: %@", filePath);
>> [self openWithPath: filePath];
>> }
>> NSLog(@"Out...");
>> }
>
>
> It is working as expected from a Terminal Shell with: 'openapp
> SaveLink
> someFile.url'.
> But nothing happens if I use the 'openWith' menu with the same file
> within
> the FileViewer of GWorkspace. Even the app is not launching at all.
>
> Here is the method:
>
>> - (void) openWithPath: (NSString *)pathFile;
>> {
>> // Get Name of the Link
>> NSString *fileName = [[pathFile lastPathComponent]
>> stringByDeletingPathExtension];
>> [name setStringValue: fileName];
>
>> // Get Link value
>> NSString *content;
>> content = [NSString stringWithContentsOfFile: pathFile];
>> NSString *url = [content substringFromIndex: 23];
>> [link setStringValue: url];
>> [savebutton setEnabled:YES];
>> }
>
>
> Do you think we must handle a different count of args with 'openWith'
> menu
> case?
I answer myself: yes, the arguments count differs and the 'lastObject'
method was the solution.
Best regards,
Patrick
--
Patrick Cardona - Pi500 - GNU/Linux aarch64 (Debian 13.3)
Xorg (1:7.7+24) - libcairo2 (1.18.4-1+rpt1 arm64) - Window Maker
(0.96.0-4)
GWorkspace (1.1.0 - 02 2025) - Theme: AGNOSTEP - Classic - MUA:
GNUMail (1.4.0 - rev.947)