OSXOperatingSystem.st
author Claus Gittinger <cg@exept.de>
Fri, 13 May 2016 13:38:44 +0200
changeset 19817 b2aaa648f81d
parent 18279 6d7174763909
child 20637 a9b41f05ca91
permissions -rw-r--r--
#DOCUMENTATION by cg class: OSXOperatingSystem comment/format in: #caseSensitiveFilenames
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17471
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
     1
"{ Package: 'stx:libbasic' }"
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
     2
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
     3
"{ NameSpace: Smalltalk }"
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
17471
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
     5
UnixOperatingSystem subclass:#OSXOperatingSystem
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
     6
	instanceVariableNames:''
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
     7
	classVariableNames:''
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
     8
	poolDictionaries:''
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
     9
	category:'OS-Unix'
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    10
!
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    11
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    12
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    13
!OSXOperatingSystem class methodsFor:'initialization'!
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    14
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    15
initializeCodeset
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    16
    super initializeCodeset.
17493
25361a7bc7e7 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17471
diff changeset
    17
    Codeset := #'utf8-mac'.
17494
4734c3c6fe43 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17493
diff changeset
    18
    CodesetEncoder := nil.
17471
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    19
! !
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
17297
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
    21
!OSXOperatingSystem class methodsFor:'dummy shell operations'!
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
    22
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
    23
openApplicationHelperCommand
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
    24
    "Return a command line helper to open a default application for file or URL"
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
    25
18279
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    26
    (self canExecuteCommand: 'open') ifTrue:[
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    27
	^ 'open'
17297
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
    28
    ].
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
    29
    ^ nil
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
    30
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
    31
    "Created: / 13-01-2015 / 09:23:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
17427
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
    32
!
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
    33
17428
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
    34
openTerminalWithCommand:shellCommand inBackground:inBackground
17427
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
    35
    "open a new terminal, which executes a command"
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
    36
17428
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
    37
    |cmd|
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
    38
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
    39
    cmd := 'osascript -e ''tell application "Terminal" to do script "%1"''' bindWith:shellCommand.
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
    40
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
    41
    inBackground ifTrue:[
18279
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    42
	^ self
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    43
	    startProcess:cmd
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    44
	    inputFrom:nil
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    45
	    outputTo:nil
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    46
	    errorTo:nil
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    47
	    auxFrom:nil
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    48
	    environment:nil
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    49
	    inDirectory:nil
17428
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
    50
    ] ifFalse:[
18279
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    51
	^ self executeCommand:cmd
17428
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
    52
    ].
17427
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
    53
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
    54
    "
17428
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
    55
     OSXOperatingSystem openTerminalWithCommand:'ls -l' inBackground:true
17427
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
    56
    "
17297
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
    57
! !
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
    58
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
!OSXOperatingSystem class methodsFor:'file queries'!
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
caseSensitiveFilenames
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    "return true, if the OS has caseSensitive file naming.
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
     On MSDOS, this will return false;
19817
b2aaa648f81d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18279
diff changeset
    64
     on a real OS, we return true.
b2aaa648f81d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18279
diff changeset
    65
     Be aware, that OSX can be configured to be either.
b2aaa648f81d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18279
diff changeset
    66
     Also, that it actually depends on the mounted volume"
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
18279
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    68
    "/ actually, this is wrong and depends on the mounted volume;
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    69
    "/ so we need a query for a particular directory (and/or volume).
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    ^ false
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    "Modified: / 5.6.1998 / 18:35:18 / cg"
16381
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
    73
!
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
    74
16644
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
    75
defaultPackagePath
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
    76
    "redefined to add stx.app packages and /Library stuff"
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
    77
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
    78
    |path executablePath executableDir packagesDir libDir vsnDirName vsnDir|
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
    79
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
    80
    path := super defaultPackagePath.
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
    81
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
    82
    executablePath := OperatingSystem pathOfSTXExecutable.
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
    83
    executablePath notNil ifTrue:[
18279
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    84
	executableDir := executablePath asFilename directory.
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    85
	packagesDir := executableDir directory directory / 'Packages'.
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    86
	packagesDir exists ifTrue:[
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    87
	    path add:packagesDir.
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    88
	].
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    89
	libDir := '/Library/Smalltalk-x' asFilename.
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    90
	libDir exists ifTrue:[
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    91
	    vsnDirName := '%1.%2' bindWith:Smalltalk majorVersionNr
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    92
				  with:Smalltalk minorVersionNr.
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    93
	    vsnDir := libDir / vsnDirName.
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    94
	    vsnDir exists ifTrue:[
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    95
		path add:vsnDir.
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    96
	    ].
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
    97
	].
16644
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
    98
    ].
16647
4c196996c402 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16644
diff changeset
    99
    ^ path
16644
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   100
!
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   101
16677
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   102
getDriveList
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   103
    "return a list of volumes in the system."
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   104
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   105
    ^ ('/Volumes' asFilename directoryContents)
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   106
      , super getDriveList
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   107
!
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   108
16381
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   109
getTrashDirectory
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   110
    "get the name of a trash folder (if the OS supports it),
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   111
     or nil, if not.
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   112
     Must be redefined to return non nil in concrete operating systems"
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   113
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   114
    ^ '~/.Trash'
16677
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   115
!
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   116
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   117
pathNameForDrive:driveName
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   118
    "given a drive name, return the pathname to open it as a directory.
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   119
     For Windows, this is the driveName itself.
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   120
     For OSX, '/Volumes' is prepended.
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   121
     Other OSs might prepent the pount point (i.e. /mnt/)"
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   122
16905
46653de3c189 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16677
diff changeset
   123
    driveName isNil ifTrue:[^ nil].
16677
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   124
    driveName asFilename isAbsolute ifTrue:[^ driveName].
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   125
    ^ '/Volumes/',driveName
17177
28ebbb908d3e class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16905
diff changeset
   126
!
28ebbb908d3e class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16905
diff changeset
   127
28ebbb908d3e class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16905
diff changeset
   128
supportsVolumes
18279
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   129
    "return true if the os support a list of drives/volumes
17179
d12edae8391b class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17177
diff changeset
   130
     (here we can return a list of mounted drives in /Volumes)"
17177
28ebbb908d3e class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16905
diff changeset
   131
28ebbb908d3e class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16905
diff changeset
   132
    ^ true
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
! !
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
!OSXOperatingSystem class methodsFor:'documentation'!
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
version
19817
b2aaa648f81d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18279
diff changeset
   138
    ^ '$Header$'
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
!
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
version_CVS
19817
b2aaa648f81d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18279
diff changeset
   142
    ^ '$Header$'
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
! !
19817
b2aaa648f81d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18279
diff changeset
   144