diff --git a/Tools/GNUmakefile b/Tools/GNUmakefile new file mode 100644 index 000000000..01a67ea8a --- /dev/null +++ b/Tools/GNUmakefile @@ -0,0 +1,59 @@ +# +# Tools makefile for NX Tools +# Copyright (C) 2020 Free Software Foundation, Inc. +# +# Written by: onflapp +# +# This file is part of the NEXTSPACE project. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this library; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02111 USA. + +ifeq ($(GNUSTEP_MAKEFILES),) + GNUSTEP_MAKEFILES := $(shell gnustep-config --variable=GNUSTEP_MAKEFILES 2>/dev/null) + ifeq ($(GNUSTEP_MAKEFILES),) + $(warning ) + $(warning Unable to obtain GNUSTEP_MAKEFILES setting from gnustep-config!) + $(warning Perhaps gnustep-make is not properly installed,) + $(warning so gnustep-config is not in your PATH.) + $(warning ) + $(warning Your PATH is currently $(PATH)) + $(warning ) + endif +endif + +ifeq ($(GNUSTEP_MAKEFILES),) + $(error You need to set GNUSTEP_MAKEFILES before compiling!) +endif + +PACKAGE_NAME = nxtools + +include $(GNUSTEP_MAKEFILES)/common.make + +# Manual pages to install +MAN1_PAGES = nxworkspace.1 nxpasteboard.1 + +# The application to be compiled +TOOL_NAME = nxworkspace nxpasteboard + +# The source files to be compiled +nxworkspace_OBJC_FILES = nxworkspace.m +nxpasteboard_OBJC_FILES = nxpasteboard.m + +include GNUmakefile.preamble + +include $(GNUSTEP_MAKEFILES)/tool.make + +include GNUmakefile.postamble diff --git a/Tools/GNUmakefile.postamble b/Tools/GNUmakefile.postamble new file mode 100644 index 000000000..f9caae83b --- /dev/null +++ b/Tools/GNUmakefile.postamble @@ -0,0 +1,79 @@ +# -*-makefile-*- +# +# Makefile.postamble +# +# Copyright (C) 2005, Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# This program is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY; without even +# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Project specific makefile rules +# +# Uncomment the targets you want. +# The double colons (::) are important, do not make them single colons +# otherwise the normal makefile rules will not be performed. +# + +# Things to do before compiling +# before-all:: + +# Things to do after compiling +# after-all:: + +# Things to do before installing +before-install:: + +# Things to do after installing +after-install:: + if [ ! -f $(GNUSTEP_SYSTEM_DOC_MAN) ]; then \ + $(MKDIRS) $(GNUSTEP_SYSTEM_DOC_MAN); \ + fi; \ + if [ ! -f $(GNUSTEP_SYSTEM_DOC_MAN)/man1 ]; then \ + $(MKDIRS) $(GNUSTEP_SYSTEM_DOC_MAN)/man1; \ + fi; \ + for file in $(MAN1_PAGES) __done; do \ + if [ $$file != __done ]; then \ + $(INSTALL_DATA) $$file $(GNUSTEP_SYSTEM_DOC_MAN)/man1/$$file; \ + which gzip && rm -f $(GNUSTEP_SYSTEM_DOC_MAN)/man1/$$file.gz \ + && gzip -9 $(GNUSTEP_SYSTEM_DOC_MAN)/man1/$$file; \ + fi; \ + done; \ + +# Things to do before uninstalling +before-uninstall:: + for file in $(MAN1_PAGES); do \ + rm -f $(GNUSTEP_SYSTEM_DOC_MAN)/man1/$$file.gz; \ + done; + -rmdir $(GNUSTEP_SYSTEM_DOC_MAN)/man1; + +# Things to do after uninstalling +# after-uninstall:: + +# Things to do before cleaning +# before-clean:: + +# Things to do after cleaning +# after-clean:: + +# Things to do before distcleaning +# before-distclean:: + +# Things to do after distcleaning +# after-distclean:: + +# Things to do before checking +# before-check:: + +# Things to do after checking +# after-check:: + diff --git a/Tools/GNUmakefile.preamble b/Tools/GNUmakefile.preamble new file mode 100644 index 000000000..6766957d6 --- /dev/null +++ b/Tools/GNUmakefile.preamble @@ -0,0 +1,59 @@ +# +# Tools makefile for nxtools +# +# Copyright (C) 2020 Free Software Foundation, Inc. +# +# This file is part of the NEXTSPACE project +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this library; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02111 USA. +# + +# Makefile.preamble +# +# Project specific makefile variables, and additional +# +# Do not put any Makefile rules in this file, instead they should +# be put into Makefile.postamble. +# + +# +# Flags dealing with compiling and linking +# + +# Additional flags to pass to the preprocessor +#ADDITIONAL_CPPFLAGS += + +# Additional flags to pass to the Objective-C compiler +#ADDITIONAL_OBJCFLAGS += + +# Additional flags to pass to the C compiler +#ADDITIONAL_CFLAGS += + +# Additional include directories the compiler should search +#ADDITIONAL_INCLUDE_DIRS += + +# Additional LDFLAGS to pass to the linker +ADDITIONAL_LDFLAGS += -lgnustep-gui + +# Additional library directories the linker should search +#ADDITIONAL_LIB_DIRS += + +# +# Flags dealing with installing and uninstalling +# + +# Additional directories to be created during installation +#ADDITIONAL_INSTALL_DIRS += diff --git a/Tools/nxpasteboard.1 b/Tools/nxpasteboard.1 new file mode 100644 index 000000000..719efdaa5 --- /dev/null +++ b/Tools/nxpasteboard.1 @@ -0,0 +1,36 @@ +.\"nxpasteboard(1) man page +.\"put together by onflapp +.\"Copyright (C) 2020 Free Software Foundation, Inc. +.\"Copying and distribution of this file, with or without modification, +.\"are permitted in any medium without royalty provided the copyright +.\"notice and this notice are preserved. +.\" +.\"Process this file with +.\"groff -man -Tascii nxpasteboard.1 +.\" +.TH NXPASTEBOARD 1 "August 2020" GNUstep "NEXTSPACE System Manual" +.SH NAME +nxpasteboard \- gives you ability to do copy & paste and invoke system services directly from command line +.SH SYNOPSIS +.B nxpasteboard [--copy] [--paste] [--service ] +.P +.SH DESCRIPTION +.P +copy reads text from the stantard input and writes it to the pasteboard +.P +paste reads text from the pasteboard and writes it to the standard output +.P +service reads text from the standard input and then calls system service to process it. System service is indentified by its name. This usually corresponds to it's menu title in the Services menu. + + echo "$PWD" | nxpasteboard --service "Terminal/Open shell here" + +If service returns any text, it will be written back to the standard output. + +.SH OPTIONS +.P +--copy copy text from standard input to the pasteboard + +--paste paste text from the pasteboard to standard output + +--service call service with text from standard input +.P diff --git a/Tools/nxpasteboard.h b/Tools/nxpasteboard.h new file mode 100644 index 000000000..4508c96c4 --- /dev/null +++ b/Tools/nxpasteboard.h @@ -0,0 +1,21 @@ +/* Include for nxworkspace tools + Copyright (C) 2020 Free Software Foundation, Inc. + + Written by: onflapp + Created: September 2020 + + This file is part of the GNUstep Project + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + You should have received a copy of the GNU General Public + License along with this program; see the file COPYING. + If not, write to the Free Software Foundation, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +void printUsage(); diff --git a/Tools/nxpasteboard.m b/Tools/nxpasteboard.m new file mode 100644 index 000000000..b69257027 --- /dev/null +++ b/Tools/nxpasteboard.m @@ -0,0 +1,127 @@ +/* Copyright (C) 2020 Free Software Foundation, Inc. + + Written by: onflapp + Created: September 2020 + + This file is part of the NEXTSPACE Project + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + You should have received a copy of the GNU General Public + License along with this program; see the file COPYING. + If not, write to the Free Software Foundation, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#import + +void printUsage() { + fprintf(stderr, "Usage: nxpasteboard [--copy] [--paste] [--service ]\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Help: gives you copy&paste and system services from command line\n"); + fprintf(stderr, "Options:\n"); + fprintf(stderr, " --copy copy text from standard input to the pasteboard\n"); + fprintf(stderr, " --paste paste text from the pasteboard to standard output\n"); + fprintf(stderr, " --service call service with text from standard input\n"); + fprintf(stderr, "\n"); +} + +int main(int argc, char** argv, char** env) { + + NSProcessInfo *pInfo; + NSArray *arguments; + CREATE_AUTORELEASE_POOL(pool); + +#ifdef GS_PASS_ARGUMENTS + [NSProcessInfo initializeWithArguments:argv count:argc environment:env_c]; +#endif + + pInfo = [NSProcessInfo processInfo]; + arguments = [pInfo arguments]; + int rv = 1; + + @try { + if ([arguments count] == 1) { + printUsage(); + rv = 1; + } + else if ([arguments containsObject: @"--copy"] == YES) { + NSFileHandle *sin = [NSFileHandle fileHandleWithStandardInput]; + NSData* data = [sin readDataToEndOfFile]; + if ([data length] > 0) { + NSString* str = [[NSString alloc ]initWithData:data encoding:NSUTF8StringEncoding]; + NSPasteboard *pboard = [NSPasteboard generalPasteboard]; + [pboard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil]; + [pboard setString:str forType:NSPasteboardTypeString]; + rv = EXIT_SUCCESS; + } + else { + rv = 4; + } + } + else if ([arguments containsObject: @"--service"] == YES) { + //suppress NSLog from NSApplication + fclose(stderr); + + //register service types, this will refresh the service manager + id app = [NSApplication sharedApplication]; + [app registerServicesMenuSendTypes:[NSArray arrayWithObject:NSPasteboardTypeString] + returnTypes:[NSArray arrayWithObject:NSPasteboardTypeString]]; + + NSFileHandle *sin = [NSFileHandle fileHandleWithStandardInput]; + NSData* data = [sin readDataToEndOfFile]; + if ([data length] > 0) { + NSString* serviceMenu = [arguments objectAtIndex:2]; + NSString* str = [[NSString alloc ]initWithData:data encoding:NSUTF8StringEncoding]; + NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName]; + [pboard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil]; + [pboard setString:str forType:NSPasteboardTypeString]; + + BOOL done = NSPerformService(serviceMenu, pboard); + + if (done) { + str = [pboard stringForType:NSPasteboardTypeString]; + if (str) { + printf("%s", [str UTF8String]); + } + rv = EXIT_SUCCESS; + } + else { + rv = 4; + } + } + else { + rv = 4; + } + } + else if ([arguments containsObject: @"--paste"] == YES) { + NSPasteboard *pboard = [NSPasteboard generalPasteboard]; + NSString* str = [pboard stringForType:NSPasteboardTypeString]; + if (str) { + printf("%s", [str UTF8String]); + rv = EXIT_SUCCESS; + } + else { + rv = 4; + } + } + else { + printUsage(); + rv = 1; + } + } + @catch (NSException* ex) { + NSLog(@"exception %@", ex); + printUsage(); + rv = 6; + } + + RELEASE(pool); + + exit(rv); +} + diff --git a/Tools/nxworkspace.1 b/Tools/nxworkspace.1 new file mode 100644 index 000000000..e869100ce --- /dev/null +++ b/Tools/nxworkspace.1 @@ -0,0 +1,46 @@ +.\"nxworkspace(1) man page +.\"put together by onflapp +.\"Copyright (C) 2020 Free Software Foundation, Inc. +.\"Copying and distribution of this file, with or without modification, +.\"are permitted in any medium without royalty provided the copyright +.\"notice and this notice are preserved. +.\" +.\"Process this file with +.\"groff -man -Tascii nxworkspace.1 +.\" +.TH NXWORKSPACE 1 "August 2020" GNUstep "NEXTSPACE System Manual" +.SH NAME +nxworkspace \- invoke Workspace commands from command line +.SH SYNOPSIS +.B nxworkspace [--open ] [--activate ] +.P +.SH DESCRIPTION +.P +nxworkspace enables you to use some of Workspace's functionality from directly command line. + +The most common use of this utility is to open a path in Workspace. Workspace will take appropriate action based on what kind of path this actuall is. + +If path is a regular file, Workspace will open it in default application. + + nxworkspace --open ~/Documents/mytext.txt + +If path is a directory, Workspace will open it in File Viewer + + nxworkspace --open . + +If path is an application, Workspace will launch it + + nxworkspace --open /Applications/Terminal.app + +You can specify which application Workspace should open path with by passing application name. + + nxworkspace --open ./nxworkspace.1 ProjectCenter + +.SH OPTIONS +.P +--open open path in Workspace + +--open open path with specific application + +--activate launch or activate application +.P diff --git a/Tools/nxworkspace.h b/Tools/nxworkspace.h new file mode 100644 index 000000000..04f3cbcb7 --- /dev/null +++ b/Tools/nxworkspace.h @@ -0,0 +1,22 @@ +/* Include for nxworkspace tools + Copyright (C) 2020 Free Software Foundation, Inc. + + Written by: onflapp + Created: September 2020 + + This file is part of the NEXTSPACE Project + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + You should have received a copy of the GNU General Public + License along with this program; see the file COPYING. + If not, write to the Free Software Foundation, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +NSString* absolutePath(NSString* path); +void printUsage(); diff --git a/Tools/nxworkspace.m b/Tools/nxworkspace.m new file mode 100644 index 000000000..120dd9bd2 --- /dev/null +++ b/Tools/nxworkspace.m @@ -0,0 +1,88 @@ +/* Copyright (C) 2020 Free Software Foundation, Inc. + + Written by: onflapp + Created: September 2020 + + This file is part of the NEXTSPACE Project + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + You should have received a copy of the GNU General Public + License along with this program; see the file COPYING. + If not, write to the Free Software Foundation, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#import + +NSString* absolutePath(NSString* path) { + if ([path isAbsolutePath]) return [path stringByStandardizingPath]; + else { + NSFileManager* fm = [NSFileManager defaultManager]; + path = [[fm currentDirectoryPath] stringByAppendingPathComponent:path]; + return [path stringByStandardizingPath]; + } +} + +void printUsage() { + fprintf(stderr, "Usage: nxworkspace [--open ] [--activate ]\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Help: invoke Workspace commands from command line\n"); + fprintf(stderr, "Options:\n"); + fprintf(stderr, " --open open path in Workspace\n"); + fprintf(stderr, " --open open path with specific application\n"); + fprintf(stderr, " --activate launch or activate application\n"); + fprintf(stderr, "\n"); +} + +int main(int argc, char** argv, char** env) +{ + NSProcessInfo *pInfo; + NSArray *arguments; + CREATE_AUTORELEASE_POOL(pool); + +#ifdef GS_PASS_ARGUMENTS + [NSProcessInfo initializeWithArguments:argv count:argc environment:env_c]; +#endif + + pInfo = [NSProcessInfo processInfo]; + arguments = [pInfo arguments]; + + @try { + if ([arguments count] == 1) { + printUsage(); + exit(1); + } + else if ([[arguments objectAtIndex:1] isEqualToString:@"--open"] && [arguments count] >= 3 ) { + NSWorkspace* ws = [NSWorkspace sharedWorkspace]; + NSString* path = absolutePath([arguments objectAtIndex:2]); + NSString* app = ([arguments count] == 4)?[arguments objectAtIndex:3]:nil; + + [ws openFile:path withApplication:app]; + } + else if ([[arguments objectAtIndex:1] isEqualToString:@"--activate"] && [arguments count] == 3) { + NSWorkspace* ws = [NSWorkspace sharedWorkspace]; + NSString* app = [arguments objectAtIndex:2]; + + [ws launchApplication:app]; + } + else { + printUsage(); + exit(1); + } + } + @catch (NSException* ex) { + NSLog(@"exception: %@", ex); + printUsage(); + exit(6); + } + + RELEASE(pool); + + exit(EXIT_SUCCESS); +} +