angesammelt seit 22 Jan 2008

Select and copy text within Quick Look previews

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

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"

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

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:
<key>system.privilege.setugid_appkit</key>
<dict>
<key>class</key>
<string>allow</string>
<key>comment</key>
<string>To allow 4D printing</string>
</dict>

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

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
Usage:
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.

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.

Spotlight

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)
miyako

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:

#!/bin/bash
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)
atTemp1{1}:="crash"
atTemp1{2}:="crash"*100
atTemp1:=1
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
LAUNCH EXTERNAL PROCESS($cmd)

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

Safari

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