apple script md5 for specific filetypes in all subfolders - applescript

i use this script to create .md5 files for each file in a folder/subfolder.
But i wish to filter to only one filetype, for example .mp4
In each folder are a lot of files, but i need only the .md5 file for the filetype .mp4
Here is the apple-script:
set theFolder to (choose folder)
tell application "System Events"
set subfolders to every folder of theFolder
repeat with eachFolder in subfolders
set fPath to (POSIX path of eachFolder)
set fName to name of eachFolder
set md5Filename to quoted form of (fName & ".md5")
do shell script "cd " & quoted form of fPath & "; /sbin/md5 -r * > " & md5Filename
end repeat
end tell
Maybe, it´s very easy and one of you can help me.
Thanks.
Excluding filetypes in apple script.

Related

How to automatically rename files when they get into folder

I've been trying to find a program or some sort of app to run all the time and check one folder. If any document would be saved in the folder it would rename it like file1.png the next one file2.png.
Transnomino has an automation feature that allows to automatically rename any file dropped in a folder using a specified renaming Recipe. The Apple Script that does this looks something like this:
on adding folder items to theAttachedFolder after receiving theNewItems
tell application "Finder" to set thePath to POSIX path of theAttachedFolder
return do shell script ¬
"open -a Transnomino --args -d \"" & thePath & "\" -r \"" & thePath & ".recipe\""
end adding folder items to
A complete guide how this can be setup is described on the website of Transnomino. Here: https://transnomino.bastiaanverreijt.com/automation/index.html

AppleScript to append date to file

I was recently able to make a drag and drop script in Automator that allowed me to zip and name a file and then automatically apply the date (DDMMYY) but now it's defaulting to (DDMMYYYY) and I can't change it. I've googled for a solution and nothing works since this needs to be at the end of the file name.
Does anyone know what I'm doing wrong or does anyone have an actual script that can help me? Everything I've found only works if the date is at the start of the file name, not at the end (but before the extension).
You can use this AppleScript inside a Run AppleScript action, it renames the archive inserting the date before the file extension
on run {input, parameters}
set thePath to POSIX path of (item 1 of input)
set currentDate to do shell script "date +%d%m%y"
set newPath to text 1 thru -5 of thePath & "_" & currentDate & ".zip"
do shell script "mv " & quoted form of thePath & space & quoted form of newPath
return {POSIX file newPath as alias}
end run
Since you didn't provide any code I can't guess how you name your files, but the way to get DDMMYY is to use shell with the do shell script command:
tell application "Finder"
set theFile to (choose file)
set theName to name of theFile
set name of theFile to theName & "_" & (do shell script "date +%d%m%y") & ".xxx"
end tell
This doesn't get rid of the file extension of the original file. For that to work you would have to use something like this:
tell application "Finder"
set theFile to (choose file)
set theName to name of theFile
set periodIndex to offset of "." in theName
set theName to text 1 thru (periodIndex - 1) of theName
set name of theFile to theName & "_" & (do shell script "date +%d%m%y") & ".xxx"
end tell
The code responsible for removing the file extension comes from this post.
You can add punctuation how you like by putting the desired symbols before the next %. So date +%d.%m.%y is possible and improves readability.

AppleScript - Change all app icons in a directory

I have folders containing applications. I want to be able to select the folder with an apple script, and have the script go through each app file in that directory, changing the icons for me.
I want to have the icon set from an image stored in the script directory.
I'd really appreciate any help because I've been trying to make this work for a while. This is my progress so far:
property appcurrentCount : 0
on run
set theFolder to (choose folder with prompt "Select the start folder")
doSomethingWith(theFolder)
end run
on doSomethingWith(aFolder)
tell application "Finder"
set subApps to every file of aFolder
repeat with eachFolder in subApps
-- replace icon here somehow
end repeat
end tell
display dialog "Count is now " & appcurrentCount & "."
end doSomethingWith
The script bellow does now what you want. As explained before, your icon file must be type icns. I now add this filter directly in the choose file command.
The selected icon will now replace ALL icons already in each Contents/Resources folder of all applications in the selected folder.
The replacement will be done preserving the name of the icns already in place.
Warning : there is no 'undo' command. your old icons are overwritten !!
set Myicon to choose file with prompt "Select Icns to be copied in every Application of the folder" of type "com.apple.icns"
set MyFolder to choose folder with prompt "Select the folder with all applications to be changed"
set Source to POSIX path of Myicon -- convert path to unix form
tell application "Finder"
set MyApps to every item of MyFolder whose name extension is "app"
display dialog "count apps=" & count of MyApps
repeat with anAps in MyApps -- loop for each App
set IcnFolder to ((anAps as string) & ":Contents:Resources:") as alias
set MyIcns to (every item of IcnFolder whose name extension is "icns")
display dialog "count of icn in " & alaps & " = " & (count of MyIcns)
repeat with oneIcon in MyIcns -- loop for each icns
set Destination to POSIX path of (oneIcon as string)
try
do shell script "cp " & (quoted form of Source) & " " & (quoted form of Destination)
end try
end repeat -- loop for each icns
end repeat -- loop for each App
end tell

Applescript Auto Open Downloaded File

How should an Apple Script look like to automatically open a file named testfile downloaded to the Downloads folder and run with a program testprogram?
I feel it should be a pretty simple template, and I am having trouble finding much to accomplish it.
This example uses Microsoft Word to open testFile.rtf. Update the code with your info and attach the folder action to your target folder.
on adding folder items to theFolder after receiving theFiles
set appPath to quoted form of (POSIX path of (path to applications folder) & "Microsoft Office 2011/Microsoft Word.app")
repeat with aFile in theFiles
tell application "Finder" to aFile's name = "testfile.rtf"
if the result then
set filePath to quoted form of aFile's POSIX path
do shell script "open -a " & appPath & space & filePath
end if
end repeat
end adding folder items to
If you manually want to open the file, try this:
set appPath to quoted form of (POSIX path of (path to applications folder) & "Microsoft Office 2011/Microsoft Word.app")
set filePath to quoted form of (POSIX path of (path to documents folder) & "testFile.rtf")
try
do shell script "open -a " & appPath & space & filePath
end try
You could create a folder action like this with Automator:
Finder's open command also has a using specifier for specifying the application:
tell application "Finder"
open POSIX file "/usr/share/doc/bash/bash.html" using (path to application "Safari")
end tell

Folder path of select file in AppleScript

I'm creating simple script to convert mp3 files using shell script. I decided to automate my conversion using applescript.
Basically what I'm doing is selecting mp3 file then splitting that file using my command line and i want to create a folder where the file is located (script will create that for me).
Now I just need to figure out how to get a path to a folder of the file.
How do I do that in applescript?
Here is the script that I have so far:
set mp3FileToSplit to choose file without invisibles
set thepath to mp3FileToSplit as text
set theposix to POSIX path of thepath
tell application "Finder" to set file_name to (name of mp3FileToSplit)
do shell script "/opt/local/bin/mp3splt -t 3.00 -d " & quoted form of file_name & " " & quoted form of theposix
Right now what that script does is creating folder on the root of my hard drive and I need to be in the folder where the file is located.
Any help will be appreciated.
tell application "Finder"
set f to POSIX file "/private/etc/" as alias
POSIX path of ((folder of f) as alias) -- /private/
end tell
Or
do shell script "dirname /private/etc/" -- /private

Resources