|
Class: OSXOperatingSystem
Object
|
+--AbstractOperatingSystem
|
+--UnixOperatingSystem
|
+--OSXOperatingSystem
- Package:
- stx:libbasic
- Category:
- OS-Unix
- Version:
- rev:
1.82
date: 2022/05/24 15:12:09
- user: cg
- file: OSXOperatingSystem.st directory: libbasic
- module: stx stc-classLibrary: libbasic
a small number of OS-X specific redefinitions here.
copyrightCOPYRIGHT (c) 2013 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
cocoa - events
-
finishLaunching
-
tell the system, that I have finished my startup phase.
OSX will stop bounding the launch icon then.
Usage example(s):
-
generateButtonEvent: button down: down x: screenX y: screenY
-
synthesize and send a button event to the screen
Usage example(s):
OperatingSystem generateButtonEvent:1 down:true x:150 y:150.
OperatingSystem generateButtonEvent:1 down:false x:150 y:150.
OperatingSystem generateButtonEvent:2 down:true x:150 y:150.
OperatingSystem generateButtonEvent:2 down:false x:150 y:150.
|
-
generateKeyboardEvent: keyCode down: down
-
synthesize and send a keyboard event to the screen
Usage example(s):
OperatingSystem generateKeyboardEvent:6 down:true.
OperatingSystem generateKeyboardEvent:6 down:false.
|
-
generateMouseMoveEventX: screenX y: screenY
-
synthesize and send a mouse move event to the screen
Usage example(s):
OperatingSystem generateMouseMoveEventX:150 y:5.
Delay waitFor:(1 seconds).
OperatingSystem generateMouseMoveEventX:1050 y:150.
|
-
getNSApp
-
get the NSApplication instance and remember in the global named NSApp
Usage example(s):
-
mouseMoveToX: screenX y: screenY
-
move the mouse to an absolute screen position
Usage example(s):
|p|
p := OperatingSystem getMousePosition.
OperatingSystem mouseMoveToX:0 y:0.
Delay waitFor:(1 seconds).
OperatingSystem mouseMoveToX:100 y:100.
Delay waitFor:(1 seconds).
OperatingSystem mouseMoveToX:p x y:p y.
|
-
receiveNextEvent
-
dummy shell operations
-
openApplicationForDocument: aFilenameOrStringOrURLString operation: operationSymbol
-
open a windows-shell/mac finder/desktop application to present the document contained in aFilenameOrString.
This is typically used to present help-files, html documents, pdf documents etc.
operationSymbol is one of:
open (i.e. like a double click on the file in the desktop)
edit
explore (i.e. like opening a finder/explorer on a directory in the desktop)
-
openApplicationHelperCommand
-
Return a command line helper to open a default application for file or URL
-
openTerminalWithCommand: shellCommand inBackground: inBackground
-
open a new terminal, which executes a command
Usage example(s):
OSXOperatingSystem openTerminalWithCommand:'ls -l' inBackground:true
|
file queries
-
caseSensitiveFilenames
-
return true, if the OS has caseSensitive file naming.
On MSDOS, this will return false;
on a real OS, we return true.
Be aware, that OSX can be configured to be either.
Also, that it actually depends on the mounted volume
-
defaultPackagePath
-
redefined to add /Application and /Library stuff
Usage example(s):
-
getDocumentsDirectory
-
return your documents directory.
Under osx, that's the user's 'Documents' folder.
The fallback for other OS's may return the user's home directory.
Usage example(s):
OperatingSystem getDocumentsDirectory
|
-
getDriveList
-
return a list of volumes in the system.
-
getTrashDirectory
-
get the name of a trash folder (if the OS supports it),
or nil, if not.
Must be redefined to return non nil in concrete operating systems
-
mimeTypeForFilename: aFilename
-
given a filename, return a corresponding mimeType.
This is placed here, to allow for OS-specific configuration
files and/or the win32 registry to be consultet.
Returns nil if no mimeType for the given name is known.
Usage example(s):
OSXOperatingSystem mimeTypeForFilename:'/Applications/Keynote.app/Contents/version.plist'
OSXOperatingSystem mimeTypeForFilename:'foo'
|
-
pathNameForDrive: driveName
-
given a drive name, return the pathname to open it as a directory.
For Windows, this is the driveName itself.
For OSX, '/Volumes' is prepended.
Other OSs might prepent the pount point (i.e. /mnt/)
-
pathOfSTXExecutable
-
return the full path of the running ST/X executable program.
Strange though, the inherited code will not be able to figure out
my path IFF ST/X is launched by the Finder (eg. click on desktop icon).
For this, we must ask NSMainBundle, which was done in the main startup code
-
supportsVolumes
-
return true if the os support a list of drives/volumes
(here we can return a list of mounted drives in /Volumes)
initialization
-
initializeCodeset
-
(comment from inherited method)
initialize the codeset, we are running under.
The codeset is determined from the environment.
The LC_CTYPE locale is set from the environment as a side effect.
interrupts & signals
-
enableHardSignalInterrupts
-
OSX sends SIGABRT for NSExceptions
-
enableUserInterrupts
-
osx seems to raise SIGUSR1 at times;
quartz - screen
-
getFrameBufferImage: displayNr
-
returns the framebuffer as an image object
Usage example(s):
self getFrameBufferImage:0
|
-
getFrameBufferImage: displayNr in: aRectangleOrNil
-
returns the frameBuffer (if rect-arg is nil)
or part of the framebuffer (if non-nil) as an image object
Usage example(s):
self getFrameBufferImage:0 in:nil
self getFrameBufferImage:0 in:(100@100 corner:301@303)
Delay waitFor:3 seconds. self getFrameBufferImage:0 in:nil
|
-
getMousePosition
-
on OSX+XQuartz, we have the top menuBar's height not included in
the x pointer position. See comment below
Usage example(s):
Delay waitForSeconds:3.
OperatingSystem getMousePosition
Display pointerPosition
(OperatingSystem getMousePosition - Display pointerPosition)
|
-
getScreenBounds: displayNr
-
returns the bounds of the screen.
This is needed, because the dimension of the XQuartz screen does not include the dock.
Usage example(s):
sound & voice
-
bestVoiceForLanguage: language
-
choose a voice as per language
Usage example(s):
OperatingSystem setVoice:'Andrea' forLanguage:'fr'
OperatingSystem setVoice:nil forLanguage:'fr'
self bestVoiceForLanguage:'de'
self bestVoiceForLanguage:'en'
self bestVoiceForLanguage:'es'
self bestVoiceForLanguage:'fr'
|
-
canPlaySound
-
(comment from inherited method)
OperatingSystem subclasses which can, redefine this
-
canSpeak
-
-
playSound: soundFile
-
use 'afplay ...'
Usage example(s):
self playSound:(Expecco::Expecco projectDirectory / 'resources/sounds/test_complete.wav')
|
-
voiceCommandSpec
-
triples are:
-
voiceInfo
-
return a list of available voices plus info:
for each available voice, a triple is returned, containing:
voiceName language_territory comment/description
Usage example(s):
OperatingSystem voiceInfo
|
-
voiceMapping
-
return a mapping from common (OS-independent) voice names
to OS-specific names or IDs.
The speak:voiceName interface will recognize both.
For portable programs, always use the OS-independent name and
let every OS xlate to its internal name.
Usage example(s):
OperatingSystem voiceMapping
|
time and date
-
getMonotonicNanosecondTime
-
This returns the nanosecond timer's value
Usage example(s):
self getMonotonicNanosecondTime
|t1 t2|
t1 := self getMonotonicNanosecondTime.
t2 := self getMonotonicNanosecondTime.
t2 - t1
|
-
getOSTimeWithNanos
-
This returns the OS time as a 2-element vector with milliseconds (as before)
plus nanoseconds.
The base of the returned value is not consistent across
different OS's - some return the number of nanoseconds since jan, 1st 1970;
others since 1900. The Time classes are prepared for this, and
convert as appropriate (by using my fromOSTime: conversion methods).
Don't use this method in application code since it is an internal (private)
interface. For compatibility use instances of Time, Date or Timestamp to work with.
* instance *
-
initInterrupts
-
initialize interrupts
Usage example(s):
SigUSR1Notification
|