Either for an Execute Applescript action, or an Execute Javascript for Automation action:
Applescript source
use AppleScript version "2.4"
use scripting additions
on run
set clip to the clipboard
if class of clip is text then
set strPruned to unlines(map(untilDigit, |lines|(clip)))
set the clipboard to strPruned
return strPruned
end if
end run
-- untilDigit :: String -> String
on untilDigit(s)
takeWhile(my notDigit, s)
end untilDigit
-- notDigit :: Char -> Bool
on notDigit(c)
not isDigit(c)
end notDigit
-- GENERIC FUNCTIONS ----------------------------------------------------
-- https://github.com/RobTrew/prelude-applescript
-- isDigit :: Char -> Bool
on isDigit(c)
set n to (id of c)
48 ≤ n and 57 ≥ n
end isDigit
-- lines :: String -> [String]
on |lines|(xs)
paragraphs of xs
end |lines|
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: First-class m => (a -> b) -> m (a -> b)
on mReturn(f)
if class of f is script then
f
else
script
property |λ| : f
end script
end if
end mReturn
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
tell mReturn(f)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to |λ|(item i of xs, i, xs)
end repeat
return lst
end tell
end map
-- takeWhile :: (a -> Bool) -> [a] -> [a]
on takeWhile(p, xs)
set bln to false
set blnText to (class of xs) is text
tell mReturn(p)
repeat with i from 1 to length of xs
if not |λ|(item i of xs) then
set bln to true
exit repeat
end if
end repeat
end tell
if bln then
if i > 1 then
if blnText then
text 1 thru (i - 1) of xs
else
items 1 thru (i - 1) of xs
end if
else
if blnText then
""
else
{}
end if
end if
else
xs
end if
end takeWhile
-- unlines :: [String] -> String
on unlines(xs)
set {dlm, my text item delimiters} to ¬
{my text item delimiters, linefeed}
set str to xs as text
set my text item delimiters to dlm
str
end unlines
Javascript source
(() => {
'use strict';
const main = () => {
// untilNumber :: String -> String
const untilNumber = takeWhile(c => !isDigit(c));
const
sa = standardAdditions(),
clip = sa.theClipboard();
return 'string' === typeof clip ? (() => {
const strPruned = unlines(
map(untilNumber, lines(clip))
);
return (
sa.setTheClipboardTo(strPruned),
strPruned
);
})() : '';
};
// GENERIC FUNCTIONS -----------------------------
// https://github.com/RobTrew/prelude-jxa
// isDigit :: Char -> Bool
const isDigit = c => {
const n = ord(c);
return 48 <= n && 57 >= n;
};
// lines :: String -> [String]
const lines = s => s.split(/[\r\n]/);
// map :: (a -> b) -> [a] -> [b]
const map = (f, xs) => xs.map(f);
// ord :: Char -> Int
const ord = c => c.codePointAt(0);
// takeWhile :: (a -> Bool) -> [a] -> [a]
const takeWhile = p => xs => {
let i = 0;
const lng = xs.length;
while ((i < lng) && p(xs[i]))(i = i + 1);
return xs.slice(0, i);
};
// unlines :: [String] -> String
const unlines = xs => xs.join('\n');
// JXA --------------------------------------------
// standardAdditions :: () -> Application
const standardAdditions = () =>
Object.assign(Application.currentApplication(), {
includeStandardAdditions: true
});
// MAIN ---
return main();
})();