angesammelt seit 22 Jan 2008

Terminal-Befehle und AppleScripts die von Interesse in der 4D-Programmierung sein könnten.

How to use the new to V14 object to enhance search of intermediate parameters stored. Example from Rob Laveaux in 4D_Tech Digest, Vol 94, Issue 40

Finding objects in arrays of objects

You can easily solve this by using an object as the root, instead an array object. The root object holds the id as the key and the settings object as the value.

For example:

` Add server A with id 12345
OB SET($server;"id";"12345";"name";"Server A";"address";"")
OB SET($settings;"12345";$server)

` Add server B with id 67890
OB SET($server;"id";"67890";"name";"Server B";"address";"")
OB SET($settings;"67890";$server)

` Get server with id 12345
$server:=OB Get($settings;"12345")

Rob Laveaux

Adding Printers to OS X from the Command Line

After a little searching, I found out you can add printers to OS X from the command line using this syntax:

lpadmin -p Printer_Name -L "Printer Location" -E -v lpd://x.x.x.x -P /Library/Printers/PPDs/Contents/Resources/en.lproj/Printer_Driver.gz

If you don’t specify the -P option, it will not show up in your Print or Printer Setup dialogs. If you want to include the generic PPD, it is located here:

/System/Library/Frameworks/ApplicationServices.framework/Versions \ /A/Frameworks/PrintCore.framework/Versions/A/Resources/Generic.ppd

That path is all one line, with no spaces.

von Steven Eppler

29 Dezember 2014

Access Safari Bookmarks from 4D

Suppose while using 4D webarea you'd like to have access to Safari-Bookmarks (which are synched between your devices since iOS8 and Yosemite if you opt in). Seems easy, this runs fine in terminal
/usr/bin/plutil -convert xml1 -o - ~/Library/Safari/Bookmarks.plist | grep -E -o 'http[s]{0,1}://.*' | grep -v icloud | sed -E 's/<\/{0,1}string>//g'


  • you need to escape the backslash "\" by "\\".
  • So the code reads
    /usr/bin/plutil -convert xml1 -o - ~/Library/Safari/Bookmarks.plist | grep -E -o 'http[s]{0,1}://.*' | grep -v icloud | sed -E 's/<\\/{0,1}string>//g'
  • the pipe "|" is a shell-command
  • This means executing the command through a shell like this $cmd:="/bin/sh -c \""+$cmd+"\""

Here the three lines in their entirety
// I keep that kind of string outside of the 4D method-editor, Xliff is just fine and supports utf-8
$cmd:=Get localized string("termSafariBookmarks")
$cmd:="/bin/sh -c \""+$cmd+"\""
LAUNCH EXTERNAL PROCESS($cmd;$in;$out;$err)
in $out there will be all bookmark-urls, linefeed-separated

28 September 2014

OSX man pages

Just wanted to share a cool tip for OSX manpages... just type the command you are about to use and want to see the manpage for, then right-click with the mouse and you get a yellow pop-up window with the manpage that you can scroll up and down and refer to while you are concocting your command without needing a second Terminal window :-) – Mark Setchell

Instantly Eject All Mounted Drives & Disks from the Command Line in Mac OS X

osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'

Let VNC viewers connect to currently logged in user

Want to connect with the currently logged in user when using a VNC viewer rather than seeing the Login Window (ARD 3.5/OS X 10.7 and later)?

sudo defaults write /Library/Preferences/com.apple.RemoteManagement VNCAlwaysStartOnConsole -bool true

Simple Image Conversion from the Command Line

To convert a single image with sips, use the following command string syntax:
sips -s format [image type] [file name] --out [output file]
For example, on a file named “test.jpg” that you want converted to PNG, the sips syntax would be:
sips -s format png test.jpg --out test.png

Select and copy text within Quick Look previews

Quick Look is a delightfully simple way to browse the contents of the files on your Mac without launching their parent apps. (Select a file, press the space bar, that's it.) But if you’re looking at, say, a PDF or Word document, Quick Look can frustrate, because it doesn't provide any way to select and copy text; if you find a snippet of text you’d like to copy and paste, you still need to launch the parent app. Unless, that is, you know a secret shared by Keir Thomas.

To make text selectable in Quick Look previews, you just need to enable a hidden Finder setting. Select and copy the code below, open Terminal (/Applications/Utilities), paste that code at the prompt, then press Return:
defaults write com.apple.finder QLEnableTextSelection -bool TRUE; killall Finder
After a second or two, the Finder will restart. Once it does, you'll be able to select text in Quick Look previews and copy it to the Clipboard for use elsewhere.

If you decide you don’t deserve to select text in Quick Look, you can turn this feature off with another Terminal command:
defaults delete com.apple.finder QLEnableTextSelection; killall Finder

Zeitzone herausfinden/Which Timezone

ganz einfach via date
date liefert einen String dieser Art: "Mi 27 Jul 2011 12:55:39 CEST"
date -u liefert "Mi 27 Jul 2011 10:55:39 UTC" als koordinierte Weltzeit

Oder das Dokument localtime auslesen
ls -al /etc/localtime
das liefert: "lrwxr-xr-x 1 root wheel 33 23 Jul 12:16 /etc/localtime -> /usr/share/zoneinfo/Europe/Berlin"

Auf Windows

WIN32API - sys_GetTimeZone

Das übrigens in der Version 5.x immer noch WIN32API heißt obwohl es 64 Bit ist :-)
Peter F.

Anyway, if you want to join PDFs on OS X from the command line, no need to install anything:

There’s a Python script hidden in Automator.app that joins PDF files

/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py --help Usage: join [--output ] [--shuffle] [--verbose]

Read the actual text content from a PDF document

Also, there are command line programs available to extract the text from PDF's that you can call with LEP. On Mac, you can also use Spotlight's mdimport command:
/usr/bin/mdimport -d2 /path/to/pdf/file.pdf >& pdf.txt
Nils Kollandsrud

Ordner öffnen, Open Folder

LAUNCH EXTERNAL PROCESS("/usr/bin/open "+Char(34)+"/Volumes/"+$Pfad+Char(34))
Pfad mit /
- Markus Weber


We've been using "ditto -c -k" to create zip-archives with LEP without any problems (with 4D 2004 and 4D v11). However, we use POSIX paths to both the directory to be archived and the archive to be created

$SourcePOSIXPath:=Convert path system to POSIX ($SourcePath)
$ArchivePOSIXPath:=Convert path system to POSIX ($ArchivePath)
$Command:="ditto -c -k '"+$SourcePOSIXPath+"' '"+$ArchivePOSIXPath+"'"

Nils Kollandsrud

Lieber Ortwin, 

schöne Sammlung. Hier könntest Du noch diese Info hinzufügen:

set zipFile_path to (Dest_theFolder & Dest_fileName & ".zip")
set cmd to "zip -r -j " & quoted form of (zipFile_path) & " " & quoted form of POSIX path of (Source_itemPath)

ZIP – Cross Platform
The zip command doesn't include anything beyond basic file metadata in the archive, while the Finder includes
them using the AppleDouble format. To include the metadata, use ditto instead 
--> Was ein oft ein gewolltes Ergebnis ist, wenn man Dateien austauschen will.

zip -r archive_name.zip folder_to_compress
unzip archive_name.zip

# -X =  without those invisible Mac resource files such as “_MACOSX” or “._Filename” and .ds store files, use 
the “-X” option in the command so:
zip -r -X archive_name.zip folder_to_compress
set zipFile_path to (Dest_theFolder & Dest_fileName & ".zip")
set cmd to "zip -r -j " & quoted form of (zipFile_path) & " " & quoted form of POSIX path of (Source_itemPath)
Store just the name of a saved file (junk the path), and do not store directory names. By default, zip will
store the full path (relative to the current directory).
Travel the directory structure recursively; for example:
                     zip -r foo.zip foo

or more concisely
                     zip -r foo foo

In this case, all the files and directories in foo are saved in a zip archive named foo.zip, including files
with names starting with ".", since  the  recursion  does not  use the shell's file-name substitution mechanism.
If you wish to include only a specific subset of the files in directory foo and its subdirectories, use the 
-i option to specify the pattern of files to be included.  You should not use -r with the name ".*", since that
matches ".."  which will attempt to  zip  up  the  parent directory (probably not what was intended).

Multiple source directories are allowed as in
	zip -r foo foo1 foo2
which first zips up foo1 and then foo2, going down each directory.

Note  that  while wildcards to -r are typically resolved while recursing down directories in the file system,
any -R, -x, and -i wildcards are applied to internal archive pathnames once the directories are scanned.
To have wildcards apply to files in subdirectories when recursing on Unix and similar systems where the shell
does wildcard  substitution,  either escape all wildcards or put all arguments with wildcards in quotes.
This lets zip see the wildcards and match files in subdirectories using them as it recurses.

Bernd Bippus

V12-Server mit OSX starten

Im Handbuch zur V12 findet sich: Under Windows, 4D Server can be launched as a Service.
Compatibility note: This function is no longer available under Mac OS starting with version 12 of 4D Server.

Wat Nu? AppleScript schreiben und dieses zum Startobjekt machen ist zumindest ein Workaround.

Das AppleScript ist einzeilig. Sage der Anwendung im Ordner, sie solle das Dokument öffnen:
tell application "/Applications/V12/4D Server.app" to open "/Mac/db-folder/DB_Name.4DC" with permissions
mit allen Erlaubnissen, sonst fragt das OS nach, ob der Server eintreffende Verbindung akzeptieren darf. Ohne Erlaubnisse wäre also hinderlich.

Finding IPs connected to your web server

On Mac OS X

note: this also shows outgoing connections from web browsers

Get all IPs connected to your web server:
netstat -nat | sed -n -e '/ESTABLISHED/p' | awk '{print $5}' | sed 's/\./ /g' | awk '{print $1"."$2"."$3"."$4}' | sort

Get all unique IPs connected to your web server:
netstat -nat | sed -n -e '/ESTABLISHED/p' | awk '{print $5}' | sed 's/\./ /g' | awk '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -n

Gefunden bei CommandLineMac

Admin-Paßwort beim Drucken: 4D 2004 und MacOSX.6

Die beiden "Showstopper" waren ja der Open Documents Bug (Crash nach x geöffneten Dokumenten) und der Print Bug (admin-Kennwort zum Drucken erforderlich). Der Open Document-Bug ist mit 10.6.3 behoben und zum Print Bug hat Bernd F. dieses aus der NUG zitiert (ville merci):

As we are/were experiencing the printing prompt for authentication when using 4D Client 2004.7 on Mac OS 10.6.x -- we've been given a solution by Jon Rhoades and passed on by Chiarelli Fabio that seems to have fixed the issue. Thank you Chiarelli and Jon!!!
etcauthentication We have solved this by adding the following key to the
/etc/authorization file:
<string>To allow 4D printing</string>

Mit einem Admin-Account ist der Spuk weg, mit einem einfachen Account nicht.

Terminal commands for improving Spotlight

Spotlight works great most of the time, but occasionally you may need to do a bit of tinkering to get it to work properly. Most of us have probably had a problem where Spotlight won't find a file you know is there. Here are a few Terminal commands for changing hidden Spotlight settings, performing more complicated searches and updating the index. …

Do you ever want or need to show all of OS X's hidden files?
Or you also should be able to call it from 4D's LEP with
defaults write com.apple.finder AppleShowAllFiles 1; killall Finder
Change the 1 to 0 to toggle the display state.
These two simple double click Applescript apps will do the job you all without you having to drag out the terminal window. yours Kevin LaTona

Set Printer Presets from the Terminal

Better check CUPS from june 2013 first.

If you want to set the printer preset from the terminal in 10.6 (or from an AppleScript via a 'do shell script' command), it's different than how it's done in previous versions of OS X.

Assuming you have a printer called 'Copy Room Printer' and a preset called 'double-sided, stapled,' you would run the following two commands:

  • defaults write com.apple.print.custompresets.forprinter.Copy_Room_Printer com.apple.print.lastPresetPref 'double-sided, stapled'
  • defaults write com.apple.print.custompresets.forprinter.Copy_Room_Printer com.apple.print.lastPresetPrefType 3
Just set the parameters to match your own needs.

Printing PDF on Mac

You can do this with the lp command line utility. For example:
lp /My_PDF_Document.pdf
There are some command line switches which give you further control.

Rob Laveaux in der iNug

Combine two PDF files into one without rasterizing

We use the python script provided in Mac OS X 10.4 and up. Location: /System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py
join [--output ] [--append] [--shuffle] [--preview] [--verbose]
Here is a sample commandline for joining two pdfs:
python '/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py' -o '/Output.pdf' '/Input1.pdf' '/Input2.pdf'
You can also use it to split a pdf into separate one-page pdf's if required.
Nils Kollandsrud

Leider nicht so zu verwenden. Schade! Python[5203] : The function `CGPDFDocumentGetMediaBox' is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance. Please use `CGPDFPageGetBoxRect' instead.

Nachtrag 29. Sep. 2010

Fred Zelinsky hat eine Lösung gefunden. Hier zum Download die beiden Methoden Combine_Pdfs_BuildAS und Gen_CompileApplescript in Textfassung.

Dazu auch Koen Van Hooreweghe:
These pythons scripts are really interesting as in the past I have created scripts for splitting a large PDF into separate pages and even overlay 2 pdf pages. The last option I use for adding a letterhead background to a PDF when it is being sent by email instead of printed on letterhead paper. The performance is a bit sluggish, but I can live with that. My scripts are based on the code I got from the join.py script which can be found in the Combine PDF Pages.action
I cannot remember exactly when, but I think OSX 10.6 made the call to CGPDFDocumentGetMediaBox obsolete and Apple actually did correct the scripts. Just take a look at the latest version.

und noch eine Perle von Koen Van Hooreweghe:
/System/Library/Printers/Libraries/./convert -f /thePostscriptfile.ps - o /thePDFfile.pdf -j application/pdf
ein PS-file in ein PDF konvertieren. AppleScript fällt aus, denn leider ist Vorschau nicht scriptable.

2. März 2012: gefunden bei And now it’s all this: Maintaining the BoundingBox in ps2pdf

MacOSX-Hints: A simple way to create PDFs from the command line

I have used many different methods over the years to print documents to PDFs from the command line. Some have been complicated sequences of pipes to and from groff, others required TeX, and occasionally I set up a "virtual" printer, simply to print to file. I recently read documentation for cups-pdf, however, and found that cupsfilter command is sufficient for most of my own tasks in its bare form!

For example, to print 80-column ASCII plaintext (the majority of my code), I can use this:

$ cupsfilter foo.txt > foo.pdf

If you find the output of that command a bit verbose (as I do), you can send the errors silently to the null device using this version:

$ cupsfilter foo.txt > foo.pdf 2> /dev/null

There are many ways to wrap this simple command even more conveniently, but I'll omit those here for now. The reason this method is ideal is because it uses built-in routines in OS X; any time you can take advantage of these, do, because many of the core technologies are significantly faster and more secure than third-party alternatives.

ich sage: stimmt, geht aber trozdem. Das folgende ins ~/.bash_profile unter OSX eingetragen erweitert mir "man" durch "pman" (=PDF man) und ist klasse!

pman() { man -t "${1}" | open -f -a /Applications/Preview.app/; }

Fazit: Einen File an open -f -a /Applications/Preview.app/; pipen und es wird ein PDF erzeugt und in Vorschau angezeigt. Dort kann es gespeichert oder verworfen werden.

Bernd Bippus


mdfind command, the UNIX API to OS X Spotlight. For example, you can find all .4dbase packages using the following syntax:
LAUNCH EXTERNAL PROCESS ("mdfind kMDItemKind='4D Database Package'";$stdIn;$stdOut;$strErr)

Can 4D Detect a USB device?

From the top of my head: use LAUNCH EXTERNAL PROCESS to execute a terminal command: system_profiler SPUSBDataType
This will return all info about the connected (and active) USB devices. You can investigate the result string if you know which info that particular printer has.
system_profiler can return XML formatted data by using the -xml option.
Koen Van Hooreweghe

Quick Look from the command line!

For all you Leopard users out there, here's a handy trick to use Quick Look from the command line. Leopard ships with a command called 'qlmanage'. The -p option shows a preview of the file passed to the command. In the terminal, type the following:

qlmanage -p thefile

You can extend this by creating the following shell script:

qlmanage -p $1 >& /dev/null &

The >& /dev/null prevents output from displaying, and the & runs the process in the background so a new prompt displays on the terminal.

Open Web Page Within Specific Browser

Cannon Smith I'm trying to use LAUNCH EXTERNAL PROCESS to open a web page in a specific browser, one that isn't the system default. This is the string I'm passing in:

open -a /Applications/Firefox.app/ http://www.apple.com/

Koen Van Hooreweghe You're right. On my 10.4 machine a saw the same thing. The url always opens in Safari. But it works this way (at least from terminal):

open -a Firefox http://www.apple.com

John DeSoi What you probably want is to use the bundle identifier. That way you don't have to depend on the application path or name. You can find an application's bundle identifier in the info.plist file inside the application.

open -b org.mozilla.firefox your_path

MIYAKO it works for me when I double quote the URL...

LAUNCH EXTERNAL PROCESS("open -a /Applications/Firefox.app \"http://www.4d-japan.com \"";$is;$ou;$err)

I need to crash 4D

Pierre Leblanc, Jerome Pupier 4D tech support came up with a very efficient trick:

Windows: LAUNCH EXTERNAL PROCESS("taskkill /IM "+Char(Quote )+"4D Developer.exe"+Char(Quote )+" /F")

Mac: LAUNCH EXTERNAL PROCESS("killall "+Char(Quote )+"4D Developer"+Char(Quote )+"")

It works every time. That's we are using to debug the Backup

Bernd F. dazu:
das ist das Gleiche wie abschiessen. Es kommt kein Dialog. Ich habe mich aber inzwischen an mein letztes Problem erinnert. Einfach ein Popup nehmen und wie folgt initialisieren:
ARRAY TEXT(atTemp1;2)
Wenn man dann im Formular mit dem Popup die Überlange Zeile auswählt, dann rummst es wie gewünscht mit OS X-Dialog.

PowerPC oder Intel-Mac?

4D Knowledgebase

Ich versuche mit 4D festzustellen, wie schnell ein Webserver antwortet.

Kannst Du testen mit dem Unixbefehl
$ ab -c 100 -n 10000 http://SERVERIP:PORT/test/hw

Procedurally Set the "Preset" Menu in Mac OS X's Print Dialog Box

Submitted by Kevin LaTona, Studio Sola

Here's a simple way to procedurally change the Print dialog window's "Presets" setting on Mac OS X.

  1. Assumptions:
  2. You are running Mac OS X.
  3. The chosen printer is already in place.
  4. You know ahead of time what the print dialog preset options name to be used is.
` Defaults command line call and a hardwired single space at the end of the line here
$cmd:="defaults write com.apple.print.custompresets com.apple.print.lastPresetPref "
` Replace "options name" with the preset name to use
$cmd:=$cmd+Char(Quote)+"options name"+Char(Quote)
` Send it to the command line using 4D

Doppelte Pfeile an beiden Enden des Rollbalkens

defaults write "Apple Global Domain" AppleScrollBarVariant DoubleBoth

Icons ausgeblendeter Programme transparent im Dock anzeigen

defaults write com.apple.Dock showhidden -bool YES

Screenshots: mit und ohne Schatten, Bildtyp

Just issue the following to disable the shadows. Use false instead of true to enable them.

defaults write com.apple.screencapture disable-shadow -bool true

There are other cool screencapture preferences you can use as well. For example, you can set the capture format to JPEG, TIFF, or PNG using the following. Google around to discover more.

defaults write com.apple.screencapture type jpeg

After setting the defaults, you must restart the SystemUI server:

killall SystemUIServer
via TUAW


Debug-Menu on and off
defaults write com.apple.Safari IncludeInternalDebugMenu 1
defaults write com.apple.Safari IncludeInternalDebugMenu 0

Noch mehr Tips in TUAW's Mac 101 and Terminal Tips sections