The cool kids use AppleScript
It’s also widely known that AppleScripters are in general happier, prettier and better smelling than any other script language users. In a perfect world there would only be one language: AppleScript(Objective-C).
The cool kids use AppleScript
It’s also widely known that AppleScripters are in general happier, prettier and better smelling than any other script language users. In a perfect world there would only be one language: AppleScript(Objective-C).
Also, since AppleScript is so verbose (bordering on logorrhea), it is good for storage sellers. A whole bunch of win-win-win points.
Unfortunately, all these advantages are apparently lost on many people: AS is not even one of the fifty most used languages (according to index | TIOBE - The Software Quality Company). A lot of convincing to do, it seems.
I really don’t know what you mean
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
set theRandomLanguage to "JavaScript"
length of theRandomLanguage
--> 10
--> Too concise
set theOneAndOnlyLanguage to ((current application's NSString's stringWithString:theRandomLanguage)'s stringByReplacingOccurrencesOfString:"Java" withString:"Apple" options:(current application's NSRegularExpressionSearch) range:{location:0, |length|:length of theRandomLanguage}) as string
length of theOneAndOnlyLanguage
--> 11
--> Just right
So I tried my luck with AppleScript but I am stuck now. For some reason I do not get the complete command concatenated.
So this is the command which works by executing it via terminal:
/usr/local/Cellar/youtube-dl/2021.3.3/bin/youtube-dl -o '~/Library/Application Support/DEVONthink 3/Inbox/%(title)s.%(ext)s' https://www.youtube.com/watch\?v\=__cjZ43g7-0
However in my script I try this:
repeat with thisRecord in theRecords
set thisName to URL of thisRecord
set params to " -o "
set theInbox to "'~/Library/Application Support/DEVONthink 3/Inbox/%(title)s.%(ext)s' "
log message thisName
do shell script "/usr/local/Cellar/youtube-dl/2021.3.3/bin/youtube-dl" & quoted form of params & quoted form of theInbox & quoted form of thisName
end repeat
And I get this error:
sh: /usr/local/Cellar/youtube-dl/2021.3.3/bin/youtube-dl -o '~/Library/Application Support/DEVONthink 3/Inbox/%(title)s.%(ext)s' https://www.youtube.com/watch?v=__cjZ43g7-0: No such file or directory
which looks exactly what I want right?
Try to omit the ~
and use the full path.
I’m stumped.
My next step would be to try running the following from script editor:
set thisName to “https://www.youtube.com/watch?v=__cjZ43g7-0”
set params to " -o "
set theInbox to "'~/Library/Application Support/DEVONthink 3/Inbox/%(title)s.%(ext)s' "
do shell script "/usr/local/Cellar/youtube-dl/2021.3.3/bin/youtube-dl" & quoted form of params & quoted form of theInbox & quoted form of thisName
This is a complete stab in the dark, it just eliminates one variable (DT/smart rules) from the equation. If it still doesn’t work, I think I’d try putting everything together as a single variable, so
set theCommand to "/usr/local/Cellar/youtube-dl/2021.3.3/bin/youtube-dl" & params & theInbox & thisName
do shell script quoted form of theCommand
Again, I don’t actually know what I’m doing - those would just be my next steps. (And I see @pete31 has also posted; he does know what he’s doing.)
@KaputtZimon and @Blanc That’s what I always do while writing a do shell script
:
Note: Code below is not working, it’s just an example how a do shell script
can be easier debugged.
set theShellScript to "/usr/local/Cellar/youtube-dl/2021.3.3/bin/youtube-dl" & quoted form of params & quoted form of theInbox & quoted form of thisName
#do shell script theShellScript
@KaputtZimon didn’t check your command further but you e.g. put -o
in straight quotes by using quoted form of
- that’s probably not what you want as you’re not doing that in the command that works in Terminal.
That was my idea too, which is why I removed the “quoted form of” for the individual sections in the second half of this post.
Yeah saw that later, sorry.
This is the script I came up with earlier today and works for me:
on performSmartRule(theRecords)
tell application id "DNtp"
repeat with theRecord in theRecords
do shell script "/usr/local/bin/youtube-dl -o '~/Library/Application Support/DEVONthink 3/Inbox/%(title)s.%(ext)s' " & URL of theRecord
end repeat
end tell
end performSmartRule
Sure can. That is on my work computer, so reproduced it here:
Looks at an RSS feed I have for one of the playlists I watch on YouTube. If the URL has YouTube in it, it uses that script on the files, and moves them to the trash now that I have the movie downloaded in my inbox.
Rick
Thanks!
thanks @jrickmd this did the the trick however I am not sure what the problem was actually. I thought I tried every combination with and without “quoted form”.
@pete31 thanks for the tip on how to debug however I am not sure if I have the best workflow.
I have a smartrule in DT with the script I am developing and everytime I change something I run it to test it in DT. However it seems that DT is caching the scripts and I did not find any way to reload it so I have to close and reopen DT everytime when I update the script which is very cumbersome.
There must be a better way right?
Now I just need to find a way to save the outcome not to the global inbox but to a specific inbox of another db. It looks like the global inbox is special in terms of “easy access”
I plan on writing a smart rule for my global inbox to move the .mp4 file to the group I want it to end up in…
Rick
hm I actually dont want the mp4 file to go to the global inbox at all since it will get synced and I dont want to get the video files synced
Try adding a Move action at the beginning of the action chain.
But this would still mean that youtube-dl
is saving to the global Inbox and then I would move the file right?
Isn’t there a way that youtube-dl
can directly save to one specific db inbox?
@pete31
thanks for the link this helps a lot!