macos - Factor Documentation

macos
Factor handbook » The implementation » System interface » Operating system detection

Prev: linux
Next: windows


Vocabulary
system

Definition
IN: system

SINGLETON: macos


Methods
USING: accessors arrays core-foundation.fsevents io.backend
io.monitors io.monitors.macos kernel system ;

M:: macos (monitor) ( path recursive? mailbox -- monitor )
path normalize-path :> path path mailbox macos-monitor
new-monitor dup [ enqueue-notifications ] curry
path 1array 0 kFSEventStreamCreateFlagFileEvents
<event-stream> >>handle ;


USING: accessors io.streams.c kernel math system terminal
terminal.macos.private unix.ffi ;

M: macos (terminal-size)
stdout-handle fileno TIOCGWINSZ winsize new
[ ioctl ] 1check 0 <
[ drop 0 0 ] [ [ ws_col>> ] [ ws_row>> ] bi ] if ;


USING: io.sockets ping system ;

M: macos <ping-port> <datagram> ;


USING: alien.libraries io.pathnames system ;

M: macos >deployed-library-path
file-name "@executable_path/../Frameworks" prepend-path ;


USING: system ui.gestures ;

M: macos action-modifier M+ ;


USING: alien.data calendar calendar.unix
io.files.info.unix.private kernel libc system time unix.time ;

M: macos adjust-time-monotonic
timestamp>timeval \ timeval new [ adjtime io-error ] keep
dup binary-zero?
[ drop instant ] [ timeval>duration since-1970 now time- ]
if ;


USING: editors.brackets io.pathnames io.standard-paths kernel
system ;

M: macos brackets-path
"io.brackets.appshell" find-native-bundle
[ "Contents/MacOS/Brackets" append-path ] [ f ] if* ;


USING: io.pathnames mason.release.sign system ;

M: macos cert-path home "config/mac_app.cer" append-path ;


USING: math.parser sequences system system-info zealot.factor ;

M: macos compile-factor-command
{ "arch" "-x86_64" "make" "-j" } cpus number>string suffix ;


USING: kernel splitting system system-info unix.sysctl ;

M: macos computer-name
{ 1 10 } sysctl-query-string "." split1 drop ;


USING: system system-info unix.sysctl ;

M: macos cpu-mhz { 6 15 } sysctl-query-uint ;


USING: system system-info unix.sysctl ;

M: macos cpus { 6 3 } sysctl-query-uint ;


USING: cocoa.plists generic io.files.temp
io.files.temp.macos.private kernel system ;

M: macos default-cache-directory
NSCachesDirectory NSUserDomainMask 1
NSSearchPathForDirectoriesInDomains plist> first-existing
[ M\ macos default-cache-directory (call-next-method) ]
unless* factor-bundle-subdir ;


USING: core-foundation.strings io.files.temp
io.files.temp.macos.private system ;

M: macos default-temp-directory
NSTemporaryDirectory CF>string factor-bundle-subdir ;


USING: generic kernel system tools.deploy.backend
tools.deploy.macos ;

M: macos deploy*
dup deploy-app-bundle?
[ deploy-app-bundle ]
[ M\ macos deploy* (call-next-method) ] if ;


USING: generic io.backend io.directories io.pathnames kernel
namespaces system tools.deploy.backend tools.deploy.config
tools.deploy.config.editor tools.deploy.macos ;

M: macos deploy-path
dup deploy-app-bundle? [
deploy-directory get [
dup deploy-config [
bundle-name "Contents/MacOS/" append-path
swap append-path normalize-path
] with-variables
] with-directory
] [ M\ macos deploy-path (call-next-method) ] if ;


USING: accessors arrays elevate elevate.macos.private
elevate.unix.private io.launcher kernel system ;

M:: macos elevated
( command replace? win-console? posix-graphical? -- process )
already-root?
[ <process> command >>command 1array ] [
posix-graphical? [ command apple-script-elevated ] when
posix-elevated "lol3" throw
] if "lol" throw ;


USING: environment.unix environment.unix.macos system ;

M: macos environ _NSGetEnviron ;


USING: io.files.info.unix kernel libc system unix.statfs.macos ;

M: macos file-system-statfs
\ statfs64 new [ statfs64-func io-error ] keep ;


USING: io.files.info.unix kernel libc system unix.statvfs.macos
;

M: macos file-system-statvfs
\ statvfs new [ statvfs-func io-error ] keep ;


USING: io.files.info io.files.info.unix.macos sequences system ;

M: macos file-systems
(file-systems) [ statfs>file-systems-info ] { } map-as ;


USING: editors.aquamacs io.pathnames io.standard-paths kernel
system ;

M: macos find-aquamacs-path
"org.gnu.Aquamacs" find-native-bundle
[ "Contents/MacOS/bin/aquamacs" append-path ] [ f ] if* ;


USING: editors.atom io.pathnames io.standard-paths kernel system
;

M: macos find-atom
"com.github.Atom" find-native-bundle
[ "Contents/MacOS/Atom" append-path ] [ f ] if* ;


USING: editors.cudatext io.pathnames io.standard-paths kernel
system ;

M: macos find-cudatext-path
"com.uvviewsoft.cudatext" find-native-bundle
[ "Contents/MacOS/cudatext" append-path ] [ f ] if* ;


USING: editors.jedit io.pathnames io.standard-paths kernel
system ;

M: macos find-jedit-path
"org.gjt.sp.jedit" find-native-bundle
[ "Contents/MacOS/jedit" append-path ] [ f ] if* ;


USING: editors.kate io.pathnames io.standard-paths kernel system
;

M: macos find-kate-path
"org.kde.Kate" find-native-bundle
[ "Contents/MacOS/kate" append-path ] [ f ] if* ;


USING: editors.lapce io.pathnames io.standard-paths kernel
system ;

M: macos find-lapce-path
"io.lapce" find-native-bundle
[ "Contents/MacOS/lapce" append-path ] [ f ] if* ;


USING: alien.libraries.finder alien.libraries.finder.macos
arrays kernel sequences system ;

M: macos find-library*
[ "lib" ".dylib" surround ] [ ".dylib" append ]
[ ".framework/" over 3append ] tri 3array
[ dyld-find ] map-find drop ;


USING: editors.lite-xl system ;

M: macos find-lite-xl-editor-path { "open" "-a" "Lite XL" } ;


USING: core-foundation.launch-services io.standard-paths system
;

M: macos find-native-bundle launch-services-path ;


USING: editors.notepadnext io.pathnames io.standard-paths kernel
sequences system ;

M: macos find-notepadnext-path
{
"com.yourcompany.NotepadNext"
"io.github.dail8859.NotepadNext"
} [
find-native-bundle
[ "Contents/MacOS/NotepadNext" append-path ] [ f ] if*
] map-find "io.github.dail8859.NotepadNext" = ;


USING: editors.pulsar io.pathnames io.standard-paths kernel
system ;

M: macos find-pulsar
"dev.pulsar-edit.pulsar" find-native-bundle
[ "Contents/MacOS/Pulsar" append-path ] [ f ] if* ;


USING: editors.rider io.pathnames io.standard-paths kernel
system ;

M: macos find-rider-path
"com.jetbrains.rider" find-native-bundle
[ "Contents/MacOS/rider" append-path ] [ f ] if* ;


USING: editors.sublime io.pathnames io.standard-paths kernel
sequences system ;

M: macos find-sublime-path
{ "com.sublimetext.3" "com.sublimetext.2" }
[ find-native-bundle ] map-find drop
[ "Contents/SharedSupport/bin/subl" append-path ] [ f ] if*
;


USING: editors.textadept io.pathnames io.standard-paths kernel
system ;

M: macos find-textadept-path
"com.textadept" find-native-bundle
[ "Contents/MacOS/textadept" append-path ] [ f ] if* ;


USING: editors.ultraedit io.pathnames io.standard-paths kernel
system ;

M: macos find-ultraedit
"com.idmcomp.uex" find-native-bundle
[ "Contents/MacOS/UltraEdit" append-path ] [ f ] if* ;


USING: editors.focus editors.focus.macos kernel make math.parser
sequences system ;

M: macos focus-command
supports-open-to-line?
[ number>string ":" glue ] [ drop ] if
[ "open" , "-a" , "Focus" , , ] { } make ;


USING: io.backend io.backend.unix.multiplexers
io.backend.unix.multiplexers.run-loop namespaces system ;

M: macos init-io <run-loop-mx> mx set-global ;


USING: ascii system ui.gestures ;

M: macos keysym>string >upper ;


USING: alien.c-types alien.data kernel openal.alut.backend
openal.alut.macos system ;

M: macos load-wav-file
0 int <ref> f void* <ref> 0 int <ref> 0 int <ref>
[ alutLoadWAVFile ] 4keep
[ [ [ int deref ] dip void* deref ] dip int deref ] dip
int deref ;


USING: elevate elevate.unix.private system ;

M: macos lowered posix-lowered ;


USING: combinators sequences system ui.gestures ;

M: macos modifiers>string
[
{
{ M+ [ "⌘" ] }
{ A+ [ "⌥" ] }
{ S+ [ "⇧" ] }
{ C+ [ "⌃" ] }
} case
] map "" concat-as ;


USING: io.files.info.unix io.files.info.unix.macos kernel system
;

M: macos new-file-info macos-file-info new ;


USING: io.files.info.unix io.files.info.unix.macos kernel system
;

M: macos new-file-system-info macos-file-system-info new ;


USING: kernel system unix.users unix.users.macos ;

M: macos new-passwd macos-passwd new ;


USING: cuda.nvcc system ;

M: macos nvcc-path "/usr/local/cuda/bin/nvcc" ;


USING: cocoa.dialogs file-picker system ;

M: macos open-file-dialog open-panel ;


USING: arrays io.launcher kernel present system webbrowser ;

M: macos open-item
present "open" swap 2array run-detached drop ;


USING: arrays system system-info system-info.macos.private ;

M: macos os-version
system-version-major system-version-minor
system-version-bugfix 3array ;


USING: accessors combinators generic kernel system unix.users ;

M: macos passwd>new-passwd
[ M\ macos passwd>new-passwd (call-next-method) ] keep {
[ pw_change>> >>change ]
[ pw_class>> >>class ]
[ pw_shell>> >>shell ]
[ pw_expire>> >>expire ]
[ pw_fields>> >>fields ]
} cleave ;


USING: system system-info unix.sysctl ;

M: macos physical-mem { 6 24 } sysctl-query-ulonglong ;


USING: accessors assocs kernel math sequences system tools.ps
tools.ps.macos.private ;

M: macos ps
procs [ kp_proc>> p_pid>> 0 > ] filter
[ kp_proc>> [ p_pid>> ] [ ps-arg ] bi ] map>alist ;


USING: cocoa.dialogs file-picker system ;

M: macos save-file-dialog save-panel ;


USING: io.backend io.files.trash io.files.trash.macos.private
system ;

M: macos send-to-trash
normalize-path <fs-ref> f kFSFileOperationDefaultOptions
FSMoveObjectToTrashSync check-err ;


USING: kernel make mason.common mason.config mason.release.sign
namespaces sequences system ;

M: macos sign-archive
{
"codesign"
"--force"
"--sign"
"Developer ID Application"
"/Users/jbenedik/config/mac_app.cer"
} over suffix short-running-process [
"xcrun" , "notarytool" , "submit" , dup ,
notary-args get % "--wait" ,
] { } make short-running-process
[ "xcrun" , "stapler" , "staple" , , ] { } make
short-running-process ;


USING: make mason.common mason.release.sign sequences system ;

M: macos sign-factor-app
{
"Factor.app/"
"libfactor.dylib"
"libfactor-ffi-test.dylib"
} [
[
"codesign" , "--entitlements" ,
"factor.entitlements" make-factor-path ,
"--option" , "runtime" , "--force" , "--sign" ,
"Developer ID Application" , cert-path ,
make-factor-path ,
] { } make short-running-process
] each ;


USING: formatting io.launcher system text-to-speech ;

M: macos speak-text "say \"%s\"" sprintf try-process ;


USING: accessors calendar.unix combinators generic
io.files.info.unix kernel system ;

M: macos stat>file-info
[ M\ macos stat>file-info (call-next-method) ] keep {
[ st_flags>> >>flags ]
[ st_gen>> >>gen ]
[ st_birthtimespec>> timespec>unix-time >>birth-time ]
} cleave ;


USING: accessors alien.strings combinators io.encodings.utf8
io.files.info.unix system ;

M: macos statfs>file-system-info
{
[ f_bsize>> >>block-size ]
[ f_iosize>> >>io-size ]
[ f_blocks>> >>blocks ]
[ f_bfree>> >>blocks-free ]
[ f_bavail>> >>blocks-available ]
[ f_files>> >>files ]
[ f_ffree>> >>files-free ]
[ f_fsid>> >>id ]
[ f_owner>> >>owner ]
[ f_type>> >>type-id ]
[ f_flags>> >>flags ]
[ f_fssubtype>> >>filesystem-subtype ]
[ f_fstypename>> utf8 alien>string >>type ]
[ f_mntonname>> utf8 alien>string >>mount-point ]
[ f_mntfromname>> utf8 alien>string >>device-name ]
} cleave ;


USING: accessors combinators io.files.info.unix system ;

M: macos statvfs>file-system-info
{
[ f_frsize>> >>preferred-block-size ]
[ f_favail>> >>files-available ]
[ f_namemax>> >>name-max ]
} cleave ;


USING: alien.strings destructors kernel libc system ;

M: macos strerror
[
1024 [ malloc &free ] keep [ strerror_r ] keepd nip
alien>native-string
] with-destructors ;


USING: formatting kernel math.parser sequences system terminfo ;

M: macos terminfo-relative-path
[ first >hex ] keep "%s/%s" sprintf ;


USING: system system-info unix.users ;

M: macos username real-user-name ;


USING: accessors calendar.unix combinators kernel system
unix.ffi unix.utmpx ;

M: macos utmpx>utmpx-record
[ new-utmpx-record ] dip {
[ ut_user>> _UTX_USERSIZE memory>string >>user ]
[ ut_id>> _UTX_IDSIZE memory>string >>id ]
[ ut_line>> _UTX_LINESIZE memory>string >>line ]
[ ut_pid>> >>pid ]
[ ut_type>> >>type ]
[ ut_tv>> timeval>unix-time >>timestamp ]
[ ut_host>> _UTX_HOSTSIZE memory>string >>host ]
} cleave ;


USING: editors.zed io.pathnames io.standard-paths kernel system
;

M: macos zed-path
"dev.zed.Zed" find-native-bundle
[ "Contents/MacOS/cli" append-path ] [ f ] if* ;

AltStyle によって変換されたページ (->オリジナル) /