I agree with these comments – scripted solutions (building your own tools) are time-consuming – much better to use something ready made and and better polished.
Just to illustrate that point (not planning to explain or support this code), you would end up having to write and integrate something like this in Sierra (ES6) JavaScript for automation:
(() => {
'use strict';
// splitAt :: Int -> [a] -> ([a],[a])
const splitAt = (n, xs) => [xs.slice(0, n), xs.slice(n)];
// intercalate :: String -> [a] -> String
const intercalate = (s, xs) => xs.join(s);
return intercalate('_',
splitAt(11,'2016-08-26-19-28-39.jpg')
.map(x => x.replace(/\-/g, ''))
);
})();
and in AppleScript, you can get into notorious tangles with the need to swap and cache “text item delimiters” all the time. Something like the JS above could be written fairly briefly as:
on run
script withoutHyphen
on lambda(x)
replace("-", "", x)
end lambda
end script
return intercalate("_", ¬
map(withoutHyphen, ¬
splitAt(11, "2016-08-26-19-28-39.jpg")))
end run
but only if you have imported (and made sense of) a whole lot of stuff like this:
-- GENERIC FUNCTIONS
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
return strJoined
end intercalate
-- 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 lambda(item i of xs, i, xs)
end repeat
return lst
end tell
end map
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property lambda : f
end script
end if
end mReturn
-- replace :: Text -> Text -> Text -> Text
on replace(strNeedle, strNew, strHayStack)
set {dlm, my text item delimiters} to {my text item delimiters, strNeedle}
set xs to text items of strHayStack
set my text item delimiters to strNew
set strReplaced to xs as text
set my text item delimiters to dlm
return strReplaced
end replace
-- splitAt :: Int -> [a] -> ([a],[a])
on splitAt(n, xs)
if n > 0 and n < length of xs then
if class of xs is text then
{items 1 thru n of xs as text, items (n + 1) thru -1 of xs as text}
else
{items 1 thru n of xs, items (n + 1) thru -1 of xs}
end if
else
if n < 1 then
{{}, xs}
else
{xs, {}}
end if
end if
end splitAt
-- splitOn :: Text -> Text -> [Text]
on splitOn(strDelim, strMain)
set {dlm, my text item delimiters} to {my text item delimiters, strDelim}
set xs to text items of strMain
set my text item delimiters to dlm
return xs
end splitOn