Aperture export import script - applescript

With macOS Catalina dropping support for Aperture, I need to move my library to a different application. Mylio has a great import tool that carries over almost all of the library structure and metadata but loses some of the adjustments. To retain those, I'm trying to write an Apple script that exports all images (with adjustments applied) in my library and reimports them into the same project before deleting the original.
I think I almost have the first part, exporting all images.
tell application "Aperture"
tell library 1
set projects to (get every project)
repeat with i from 1 to count of projects
tell (item i of projects)
export its every image version naming folders with folder naming policy ¬
"Project Name" using export setting ¬
"JPEG - Original Size" to (choose folder with prompt "Choose an export folder")
end tell
end repeat
end tell
end tell
However, when I try to run this script, I keep getting the error
apertureExportImport.applescript:704:712:
execution error: Aperture got an error: Can’t make {project id "1ixjjya6T+Sb3pFmhRK8Fg"} into type project. (-1700)
I guess the problem is with set projects to (get every project) but I can't find any examples online from which to figure out what else to write here.

I don't use Aperture, so I can only take an educated guess:
From the error message, I can be reasonably sure that project is an AppleScript object, specifically an element that, from your script, I'll assume belongs to a library object. In that case, there will almost certainly be a plural element form named "projects" already defined , which would refer to a collection of (i.e. multiple) elements that are all of type project.
Therefore, the following line:
set projects to (get every project)
is problematic, because you're attempting to redefine a class object that belongs to AppleScript. In fact, projects will be shorthand for every project, so this should already be defined in the way that you want, and simply removing this line completely should be sufficient.
On a separate note, it looks like (from you script) the export command can be passed a collection of objects as its direct parameter, which you’re doing with export its every image.... Assuming this is valid, then it might be able to export all images in all projects at once:
tell application "Aperture" to export every image version in every project of library 1 ¬
naming folders with folder naming policy "Project Name" using export setting ¬
"JPEG - Original Size" to (choose folder with prompt "Choose an export folder")

I got it working in the end (everything except deleting the original images after exporting and reimporting but that I can simply do manually by flagging or color-coding all images the script will handle).
tell application "Aperture"
with timeout of 86400 seconds
activate
set exportSetting to export setting "JPEG - Original Size"
set folderPolicy to folder naming policy "Project Name"
set exportFolder to "/Users/<user>/Desktop"
-- Alternatively, use
-- set exportFolder to (choose folder with prompt "Choose an export folder")
tell library 1
repeat with proj in projects
set imageSel to every image version in proj where flagged is true
export imageSel naming folders with folderPolicy using exportSetting to exportFolder
set importFolder to exportFolder & "/" & name of proj
import importFolder by referencing into proj
end repeat
end tell
end timeout
end tell
One important lesson that was hard to learn is that exportSetting and folderPolicy need to be set in the context of the entire library (i.e. at the very start of the script) rather than on a per-project level to avoid the error
execution error: Aperture got an error: Can’t get folder naming policy "Project Name". (-1728)

Related

moving one folder to another folder - applescript

I'm trying to move a user-selected folder to another folder, but I don't get it: whenever I look it up, it looks too complicated, even though I know it's not supposed to be.
Here's the code I have so far - please help:
choose folder with prompt "Select folder:"
on open of finderObject
tell application "Finder" to move (finderObject) to folder "Library:Application Support"
end open
end
First off, you have to assign the chosen folder to a variable.
Also, many special folders in the OSX file structure have special names to get their paths, including the library and the application support folders. So, your script can simply be:
set finderObject to choose folder with prompt "Select folder:"
tell app "Finder" to move finderObject to folder (path to Application Support folder from local domain as string)
However, that is the root level Library folder. I suspect you will want to use the Application Support folder in the ~/ user domain. For that, change the "from local domain" to "from user domain".

AppleScript to open all files in a folder, one by one. Alias list to carry filename for pasting later?

I have hundreds of custom FileMaker Pro .fp7 files that I need to Open, menu item "Export Script..." for and save. Here's what I have so far.
tell application "Finder"
set fl to files of folder POSIX file "/Users/EDITOR/Desktop/DROP/" as alias list
end tell
repeat with f in fl
tell application "FileMaker Pro"open f
activate
end tell
tell application "System Events"
tell process "FileMaker Pro"
click menu item "Export Script..." of menu "File" of menu bar item "File" of menu bar 1 of application process "FileMaker Pro" of application "System Events"
delay 0.4
keystroke "/Users/EDITOR/Desktop/DROP/"
end tell
end tell
end repeat
My challenge is this: FileMaker Pro wont carry the filename into the Export name window. It only says Untitled.tab. Is there a way to either source and copy the filename as it's being opened or alias'd? Either hold it in the clipboard to paste later...or, have the repeat function pause for me to type each .tab filename.
Thanks,
G.
Two ideas:
One -- if you're using Filemaker Pro 9, 10, 11, or 12 (possibly earlier versions too, I'm not sure,) you could write a custom script in Filemaker that uses the Export Records script step, programmatically specifying (through a local or global variable) a custom file name for each export. Be sure when you set the variable that you include the appropriate extension depending on what format you export to, i.e. .csv, .tab, .xls, etc.
Once you get the script working correctly, tick the "Perform without dialog" option so it will process & exit silently without you having to interact with each export action.
Two - If all else fails, you might look into using a third-party keyboard / scripting utility called "Keyboard Maestro". It has lots of functionality, including the ability to interact via Applescript and, I believe, to pass args to and from shell scripts.
Possibly "Keyboard Maestro" could be used to paste the filename into FMP's export/save-as... dialog box.
Import all database files into one master version. Without this step FileMaker is unusable.
It is then easy to generate the smaller fm files with detail data out of the master.

Send all files on Desktop to Evernote then delete

Good morning,
I am trying to write an AppleScript that I can run that will send all the files on my desktop to Evernote, and then delete the files. My code to date is:
on run {input}
tell application "Finder"
select every file of desktop
end tell
tell application "Evernote"
repeat with SelectedFile in input
try
create note from file SelectedFile notebook "Auto Import"
end try
end repeat
end tell
tell application "Finder"
delete every file of desktop
end tell
end run
If I run this then the first and last 'tell' work fine (ie. the script highlights then deletes all the files on the desktop), but the middle 'tell' doesn't do anything.
However, if I manually highlight all the files on the desktop and then run just the middle 'tell' then it imports fine - each item into a separate note as intended.
As you can tell, I am new to AppleScript - I suspect I need to put the selected files in an array of some sort, but can't figure it out. Help!
Many thanks
Rich
Your code fails because there is no relation between your input variable and the selection of files via Finder – which means that your list is empty, and Evernote is not processing anything at all. You have obfuscated the problem by wrapping the Evernote import command in a try block without any error processing, which means all errors just go unnoticed (to avoid this kind of problem, it is good practice to always log the error message in an on error clause, if nothing else).
Also, you don’t actually need to select files on the Desktop via AppleScript to process them. The following code will grab all visible files (excluding pseudo-files like packages / apps):
tell application "System Events"
set desktopFiles to every disk item of (desktop folder of user domain) whose visible is true and class is file
end tell
Pass the list you retrieved that way to Evernote for processing:
repeat with aFile in desktopFiles as list
try
tell application "Evernote" to create note from file (aFile as alias) notebook "Auto Import"
tell application "System Events" to delete aFile
on error errorMessage
log errorMessage
end try
end repeat
and you are good to go.
Note that by judiciously placing the deletion command (right after the import command, inside the try block, inside the loop over all files), you make sure it is only called if Evernote does not error on import while avoiding having to iterate over the files several times.
A final note: you don’t have to use the block syntax for tell statements if there is only one command to execute – using tell <target> to <command> is easier and will keep you out of nested context hell.
Thanks #adayzone for corrections on list handling and alias coercion
Try
tell application "System Events" to set xxx to get every file of (desktop folder of user domain) whose visible is true
repeat with i from 1 to count of xxx
set SelectedFile to item i of xxx as alias
try
tell application "Evernote" to create note from file SelectedFile notebook "Auto Import"
tell application "Finder" to delete SelectedFile
end try
end repeat
Thanks #fanaugen

Create AppleScript for a program that isn't installed on the current computer

I'm trying to make two copies of an AppleScript, one that works for Entourage and one for out Outlook. I only have Entourage installed on the current computer.
According to the info on Microsoft's site, both applications have the same library of AppleScript commands, and I should be able to simply change the application name referenced within the script.
Changing:
Tell application "Microsoft Entourage"
to
Tell application "Microsoft Outlook"
Prevents me from saving the script because I don't have outlook installed on this computer. Is there any way around this? Do I need to use a text editor to edit the actual script file and change it there?
Thanks!
The following work-around may do the trick. On the computer where Entourage is installed, a using terms directive will let you compile the script, even if Outlook is not installed:
set theApp to a reference to application "Microsoft Outlook"
using terms from application "Microsoft Entourage"
tell theApp
get version
...
end tell
end using terms from
Upon compiling and saving the script the AppleScript Editor will bug you about the missing Outlook application, but it will nevertheless produce a compiled AppleScript file (.scpt).
Applescript is a pre-complied file format, meaning that every time you click "Save" it runs through a series of steps to ensure the script will work, but just short of actually running through the script's logic. Part of those steps is to look for the application to see if it exists on the Mac.
In short, if you want to save the script as an Applescript, you need the target application installed, otherwise you can save the script as a text file and move the file over to the target Mac to save as an Applescript over there.
It should be possible to make one script that works with both Entourage and Outlook, without bugging you if one isn't found either when you compile or when you run. I don't have either Entourage or Outlook but it should work like this:
using terms from application "Microsoft Entourage"
script theScript
tell application "Finder" to try
set theApp to application file id "Entourage's Bundle ID" as text
on error
set theApp to application file id "Outlook's Bundle ID" as text
end try
tell application theApp
-- do stuff
end tell
end script
end using terms from
store script theScript in "MyScript.scpt"
"using terms from" is only relevant when compiling the script - it isn't needed when running, though for some reason you'll still get bugged if that app isn't found. So by wrapping it around a script object and then writing out that script to file, the resultant script will still run but won't contain "using terms from" and so won't bug the user.
For getting a reference to the right app, Finder can look for it by ID and simply error if it isn't found rather than bugging the user. You'll need to insert the proper ID's there, I don't know what they are.

How to automate XCode project alterations?

I have a tedious task that I need to repeat every time I build my iPhone project for sending to non-programmer colleagues: all libraries and headers that I reference outside the project's folder need to be copied into the project folder or a subfolder thereof, so I can zip up the source and pass it on.
I'm aware that you can automate XCode with AppleScript, but I can't for the life of me find any proper documentation of the commands available. If I google XCode AppleScript automation, I just get a bunch of hits on writing AppleScript apps in Xcode.
Any help will be greatly appreciated!
here's a demo to get you started. since you know how to locate the dictionary, the rest may be easy if you are comfortable using AppleScript:
tell application "Xcode"
-- of course, use your project's name instead of Alias
set projectName to "Alias"
set xcProject to project projectName
repeat with idx from 1 to the count of (get every file reference of xcProject)
set fileRef to (file reference idx) of xcProject
get path of fileRef
get id of fileRef
get name of fileRef
get properties of fileRef
set newPath to path of fileRef
-- add logic and alterations here
set path of fileRef to newPath
-- ...
end repeat
end tell
based on your description, it would be easier to create a custom target in xcode to perform this task. xcode can run all sorts of unix utilities for copying, zipping, etc. soo... shell scripting should be much easier. you can also set this target up as a dependency if you'd like, so it always stays up to date (but a little slow for regular development, tbh.
yeah, you can use applescript with xcode in many cases, but it is going to be much more difficult for the task you've outlined.

Resources