Using Shortcuts I’m creating a shortcut that will open Omnifocus then open a perspective (which is set up to open in a new window). However, instead of opening in a new window the perspective replaces the existing window. I use this URL to open the perspective:
omnifocus:///perspective/Myperspective
Is there a modifier I should be adding to this to get it to open in its own window?
Thanks for any help.
I created this Shortcut to accomplish what you’ve just requested. Tell me if it works for you:
Shortcut link:
https://www.icloud.com/shortcuts/94ed38b5d96941478c1ff2ba23a3b335
Script code:
// OMNI JS CODE ---------------------------------------
const omniJSContext = strName => {
const main = () => {
const
strPerspective = argument.input,
mbPerspective = find(
x => x.name === strPerspective
)(Perspective.all)
return bindMay(
mbPerspective
)(
p => document
.newWindow()
.then(
w => w.perspective = p
)
)
};
// GENERICS ----------------------------------------------------------------
// https://github.com/RobTrew/prelude-jxa
// JS Prelude --------------------------------------------------
// Just :: a -> Maybe a
const Just = x => ({
type: "Maybe",
Nothing: false,
Just: x
});
// Nothing :: Maybe a
const Nothing = () => ({
type: "Maybe",
Nothing: true
});
// Tuple (,) :: a -> b -> (a, b)
const Tuple = a =>
// A pair of values, possibly of
// different types.
b => ({
type: "Tuple",
"0": a,
"1": b,
length: 2,
*[Symbol.iterator]() {
for (const k in this) {
if (!isNaN(k)) {
yield this[k];
}
}
}
});
// bindMay (>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b
const bindMay = mb =>
// Nothing if mb is Nothing, or the application of the
// (a -> Maybe b) function mf to the contents of mb.
mf => mb.Nothing ? (
mb
) : mf(mb.Just);
// cycle :: [a] -> Generator [a]
const cycle = function* (xs) {
// An infinite repetition of xs,
// from which an arbitrary prefix
// may be taken.
const lng = xs.length;
let i = 0;
while (true) {
yield xs[i];
i = (1 + i) % lng;
}
};
// find :: (a -> Bool) -> [a] -> Maybe a
const find = p =>
// Just the first element in xs which
// matches the predicate p, or
// Nothing if no match is found.
xs => xs.constructor.constructor.name !== (
"GeneratorFunction"
) ? (() => {
const i = xs.findIndex(p);
return -1 !== i ? (
Just(xs[i])
) : Nothing();
})() : findGen(p)(xs);
// findGen :: (a -> Bool) -> Gen [a] -> Maybe a
const findGen = p =>
// Just the first match for the predicate p
// in the generator stream xs, or Nothing
// if no match is found.
xs => {
const
mb = until(
([nxt]) => nxt.done || p(nxt.value)
)(
([, b]) => Tuple(b.next())(
b
)
)(Tuple(xs.next())(xs))[0];
return mb.done ? (
Nothing()
) : Just(mb.value);
};
// first :: (a -> b) -> ((a, c) -> (b, c))
const first = f =>
// A simple function lifted to one which applies
// to a tuple, transforming only its first item.
([x, y]) => Tuple(f(x))(y);
// length :: [a] -> Int
const length = xs =>
// Returns Infinity over objects without finite
// length. This enables zip and zipWith to choose
// the shorter argument when one is non-finite,
// like cycle, repeat etc
"GeneratorFunction" !== xs.constructor
.constructor.name ? (
xs.length
) : Infinity;
// or :: [Bool] -> Bool
const or = xs =>
xs.some(Boolean);
// repeat :: a -> Generator [a]
const repeat = function* (x) {
while (true) {
yield x;
}
};
// until :: (a -> Bool) -> (a -> a) -> a -> a
const until = p =>
// The value resulting from repeated applications
// of f to the seed value x, terminating when
// that result returns true for the predicate p.
f => x => {
let v = x;
while (!p(v)) {
v = f(v);
}
return v;
};
return main();
};
omniJSContext()
1 Like