Applescript/automator : move all the files listed in a document - macos

I'm completely rebuilding a shared iTunes library and this needs to be team work.
I found a way to work the XML database in Google Drive so that we can all edit the track list simultaneously (>7500 entries). The spreadsheet contains for every song the path to the corresponding file.
Now I need a script to move the tracks listed in that spreadsheet to a common folder, so I can separate the songs we decided to keep from the ones we don't want anymore.
The blueprint I imagined for the code is basically :
Get the paths list (txt, csv, etc. doesn't matter) and store it as
an array.
Rotate through that array and select+move to a common folder each file pointed by the paths.
I'm not expecting any ready-to-use solution, but I would really appreciate some tips or pieces of advice that could make me spare a lot of time.
I also have to admit I have limited knowledge in Mac OS X programming (more used to web and windows environments) and have no experience in Applescripts.
However, I feel that what I'm trying to achieve is pretty straightforward and could help other people as well.

there are just 2 items not clear in your request :
1) what is the file type in which file paths are stored ? I assumed it is a text file
2) which format the paths have ? is it Unix format (like HD/Users/My_User/Desktop/My_Song), or is is a Finder format (like HD:Users:My_User:Desktop:My_Song). I assume it is a finder format
then script bellow asks you to select the text file, read it, ask you to select destination folder and move every file described in text file to the destination folder.
tell application "Finder"
set TextFile to (choose file with prompt "Select your text file" of type {"txt"})
set My_Folder to choose folder with prompt "Select your destination folder"
set List_files to paragraphs of (read TextFile)
move List_files to My_Folder
end tell
the "move" can be changed to a "copy", if required

Thank you so much to both of you for your answers.
Regarding pbell's questions :
1. I did not specify the format of the file containing the paths because I wasn't sure which ones the script could handle. Now I will make sure it is in a txt format.
2. The paths are actually il a Unix format, but seeing your example it looks pretty easy to parse. Can I just replace every "/" with a ":" ..?
I will try your code this afternoon. Again thanks a lot for caring and for sharing your time and knowledge.
Terence

Works like a charm !
Thank you very much pbell, your code works perfectly. I just had to make a txt file with Finder-formatted paths like so :
Macintosh HD:Users:FirstnameSurname:Desktop:Music:November-7:Season 3:04 Parasite.mp3
Macintosh HD:Users:FirstnameSurname:Desktop:Music:November-7:Season 3:05 Nowhere.mp3
Macintosh HD:Users:FirstnameSurname:Desktop:Music:November-7:Season 3:06 Amber Light.mp3
We spared so much time thanks to you.
Have a great day,
Terence

Related

for loop command with multiple variables

I am very new to command line and script language, and not so familiar with terms. I will try my best to explain my issue.
I am trying to edit/compress my ebooks in bulk process, and here comes the Calibre.
Calibre is the ebook editing software to make some changes to my epub files.
It's quite feature rich and in most cases easy to use, but only and biggest downside is whenever I edit/covert/read books in the GUI interface I first have to add books in the library, which involves making copy of every file into calibre's predefined directory. and on editor's GUI I can only edit one file at a time.
I have thousands of ebooks to edit, it will take days to do so, it's also bad for my storage space. Big NO NO.
Thankfully, it is possible to compress images in mass on command line interface with the help of useful plugin to asssist with handling bulk files.
for /r "C:\Users\foldername" %v in (*.epub) do calibre-debug -r "Editor Chains" "Compress Images" "%v" "%v.epub"
It works just as expected. it scans all epub files in that folder and its subfolders, and call the plugin to do its job - compress images - and save the output files in the same folder, adding the ".epub" extension to the name of original file name to avoid duplicate.(e.g. this is a book.epub --> this is a book.epub.epub)
Only problem is I have yet to find a way to save the output files in a different folder, with same file name. maybe there's something I am missing or it's just not possible.
If anyone knows how, please let me know.
I've tried:
for /r "C:\Users\foldername" %v & "C:\Users\newfoldername" %x in (*.epub) do calibre-debug -r "Editor Chains" "Compress Images" "%v" "%x"
... and it obviously failed, haha.

How to use Automator and Applescript to batch move files/folders to a specified folder based on specific text in Calendar Events, MacOS

Every day, I get up to 25 real estate photoshoots from a photographer, edit them, and export them into their respective realtors' folder in Dropbox. I get each shoot from the photographer in a folder named with its respective address/location. Currently, after editing each shoot, I look at the foldername (the address/location), go to the Calendar app, find which event has that location, see who the respective realtor is, navigate to their personal folder or create it if it doesn't exist, and then export the photoshoot into their folder (the realtor's name). Every. Single. Time.
I'm trying to automate this process by simply exporting all the shoots into one folder, triggering an Automator Folder Action which sorts the shoots into their respective realtor's folder, based on the foldername.
The relationship between the source folders and destination folders is determined based on location data from a Calendar Event. I've already figured out how to pull the data from Calendar, but getting Automator to move the folders around using the data has me thoroughly stumped.
I've tried several things in Automator, and I'm sure there's a simple way using Applescript but I haven't learned enough about Applescript to make it work. I've tried copy/pasting bits of Applescript code from other posts but I've finally thrown my hands up and decided to ask the experts lol. Here are some screenshots to help illustrate the issue.
Folders full of pictures "Test"(Sources):
"Realtors" Folder (Destinations)
Here is the Automator Workflow I've created so far, which pulls the address (Source foldername) and realtor names (Destination foldername [with other junk to be removed]) from Calendar event data, and creates 2 txt files (shown in the screenshot after this one):
Text files created by above workflow:
It's possible that I'm overcomplicating this horribly, but the solution that comes to mind is this: The text files correlate based on line number, i.e. line 1 of "Today's Locations.txt" (Location: 326 Whiterock Dr) corresponds with line 1 of "Today's Shoots.txt" (Summary: Photos for Remy Locasio).
When I drop these folders into the trigger folder, "Test" in this case, Automator/Applescript could search the "Today's Locations.txt" file for "326 Whiterock Dr" and say, "Hey, that's on line 1. I'm gonna go into "Today's Shoots.txt",find line 1, parse out (Summary: Photos for ), take the realtor's name only (Remy Locasio) and move the input folder ("326 Whiterock Dr") into the realtor's folder with that name ("Remy Locasio"), then do it again for the next folder and it's corresponding documents' line, etc etc, until all the folders are moved.
Before the realtor's name is typically the word "for ". Whether it's Photos for , Photos and videos for , Photos and aerial photos for etc. so "for " could be a delimiter maybe?
Sometimes, after the realtor's name, there's a note, always separated by a " (", eg. Brandi Smith (text when on the way), so " (" could be another delimiter maybe?
Sometimes the realtor's name is spelled wrong in the calendar but not in the folder, as is the case with Brandi vs Brandy Smith on line 9. There would need to be a popup in this case asking for the correct folder. Something to the effect of "Could not find a folder called "Brandi Smith". Should we create it or choose another folder? and I'd choose the correct folder, or in the case of "Megan Forsberg" (line 8) who doesn't have a folder yet, allow it to create the folder.
I've racked my brain for a week trying to do this with Automator and variables and I'm at a complete loss, any help would be a godsend. I'll gladly clarify anything that doesn't make sense or answer any questions anyone has.
I can't understand the whole problem clearly but you can use below code in the applescript for the regex part.
set a to "Photos for Karie Williams (Zonker)"
set b to do shell script "str='" & a & "';sed 's/(.*//g' <<< $str"
set c to do shell script "inp='" & b & "';sed 's/.*\\(for \\)//' <<< $inp"
display dialog c

How to replace all files with a specific pixel size, and keep their names?

I have a .png file and a folder with multiple folders in it, that all contain multiple .png files, e.g. '1.png', '2.png' and so on. What I'd like to do is to replace the contents of all those files to the first named file, but keep their names.
I'm pretty sure this is doable and I think I found an answer to do this in one folder using command prompt on Windows, but I'd also like to only replace files that have a specific file size (in pixels, and not the same size as the file I'm replacing them to, just a specific file size).
I prefer to do this simply using a batch file, so if anyone can help that'd be appreciated a lot. If it's not possible to meet the file size criteria with a batch file, but it is possible to do this for a whole directory tree with .png files, that gets me a long way as well.
Thank you in advance!
Edit: In the comments Stephan mentioned you can't get the pixel size of a file, so it turns out this isn't possible. I'm not going to bother with an external application.

PowerBuilder and batch processing

I'm using PowerBuilder 10.5 and as a newbie I'm a bit stuck and since Google isn't giving me a satisfying answer I'm asking some advice from the Stack Overflow group.
I have a Rich Text Edit field in which the user can write something, insert pictures and so forth. Once finished, he goes to the „Search“ command button and clicking it searches for the batch file that will suit his needs (copy that text into an existing word document, create a new word and place the folder on web, and so fort – there are 6 different batches). The code in the clicked event of „Search“ command button is this:
String ls_s
GetFileOpenName('PB_app', ls_s, ls_s, 'BAT', "Win Batch Files (*.BAT),*.BAT", 'C:\Programs\Test')
And here come my problems: I can't connect my app and the selected batch file. I'd like the path of the selected batch file to be visible in the Single Line Edit filed, but I have no idea how to get there, not to mention I'm point blank at how to connect PB app, batch file, how to even say to the batch file – „That text in rich text edit field is the one you have to work with?“…?
So I need some advice, guidance, perhaps some links or names of any literature that would help me understand how it should be done. I've lost two days and got nowhere, and I just need some piece of advice to get me going…
Your problem is that the original programmer used one variable for two return values. If you declare a new string variable and pass it instead of the first ls_s, you'll see this will return you the path. If you run into trouble, PB has a good help file (and the manuals are also online) which covers GetFileOpenName().
Good luck,
Terry

What are macid filetypes in excel vba

What are all the possible MacID("filetype")
I need the one specifically for CSV but i couldn't find a list anywhere online surprisingly.
Just a little aside for this thread.
Yes there are few places to find details of the MacIDs, but beware.
If a file is create on a PC it may not have its MacID set correctly, or at all for that matter.
I am working with Excel files created on both platforms. The XLSX ID is correct if the file is made on Mac but is empty if made on PC.
I have found the best solution is to ignore both forms of wildcards for the two platforms and instead just load all files and use the extension .xlsx
Hope this helps someone
Bob J.
First run:
mdls "FileName"
Find the TypeCode in the Output:
kMDItemFSTypeCode = "TEXT"
You can use:
Dir(Path,MacID("TEXT"))

Resources