Now that Bike 1.9 Preview (103) rewards full-screen mode with centering, and with various Focus
, Typewriter
and Wrap
options, it seems appealing to be able to toggle Full Screen view by keyboard.
( I think Apple provides no default keyboard binding for this ?)
Here is a script which you can bind to a keystroke with something like Keyboard Maestro or Fastscripts, and which you can test in Script Editor, with the language selector at top left set to JavaScript
.
Expand disclosure triangle to view JS source
(() => {
"use strict";
// -- TOGGLE FULL-SCREEN VIEW STATE OF FRONT WINDOW --
// Rob Trew @2023
// Ver 0.01
// main :: IO ()
const main = () => {
const
proc = Application("System Events")
.applicationProcesses.where({
frontmost: true
}).at(0);
return either(
alert("Toggle full screen view")
)(
([k, v]) =>
`${k} -> ${v ? "Full" : "Normal"} screen.`
)(
bindLR(
proc.exists()
? Right([
proc.name(),
proc.windows.where({
subrole: "AXStandardWindow"
}).at(0)
])
: Left("No front application found.")
)(
([appName, w]) => bindLR(
w.exists()
? Right(
w.attributes.where({
name: "AXFullScreen"
}).at(0)
)
: Left(
`This ${appName} window lacks a full-screen mode.`
)
)(
attr => attr.exists()
? Right([
appName,
attr.value = !attr.value()
])
: Left("No full screen mode for this window.")
)
)
);
};
// ----------------------- JXA -----------------------
// alert :: String => String -> IO String
const alert = title =>
s => {
const sa = Object.assign(
Application("System Events"), {
includeStandardAdditions: true
});
return (
sa.activate(),
sa.displayDialog(s, {
withTitle: title,
buttons: ["OK"],
defaultButton: "OK"
}),
s
);
};
// --------------------- GENERIC ---------------------
// Left :: a -> Either a b
const Left = x => ({
type: "Either",
Left: x
});
// Right :: b -> Either a b
const Right = x => ({
type: "Either",
Right: x
});
// bindLR (>>=) :: Either a ->
// (a -> Either b) -> Either b
const bindLR = m =>
mf => m.Left ? (
m
) : mf(m.Right);
// either :: (a -> c) -> (b -> c) -> Either a b -> c
const either = fl =>
// Application of the function fl to the
// contents of any Left value in e, or
// the application of fr to its Right value.
fr => e => "Left" in e ? (
fl(e.Left)
) : fr(e.Right);
// MAIN ---
return main();
})();
A Keyboard Maestro version, initially bound to ⌥. (opt + period)
Toggle full screen.kmmacros.zip (2.2 KB)
UPDATE
Foolish of me
I failed to spot that Bike already provides the keybinding ^⌘F
(And perhaps this is indeed an Apple default now ?)
(I’ll leave the script and macro there, just in case anyone finds they can use it in another context)