Getting path in iPhotoLibrary by photo id using applescript - image

I try to select the path in the iPhotoLibrary of a photo by its id using the following Applescript:
tell application "iPhoto"
set photoID to 25801
set thePhoto to photo id (photoID + 2 ^ 32)
set photoPath to image path of thePhoto
end tell
That doesn't work because Applescript told me, that it's not possible to convert 4.294993097E+9 to integer. I wrote (photoID + 2 ^ 32) as number and Applescript wasn't able to got the image path.
Please told me what was my mistake and how can I solve the problem.

You must first get the 'Photo' object from the ID by a search in iPhoto, then only get the path of that object:
set myPhoto to first item of (every photo whose id is myId)
set myPath to image path of myPhoto
myPath is the complete file path in Unix format (with'/' and not ':')

Related

Converting AppleScript to SwiftAutomation

This AppleScript that I found here does what I want:
tell application "iTunes"
set matchtrack to tracks in playlist 1 whose persistent ID is "C70EA9CDC276CB6D"
if matchtrack is not {} then
return name of item 1 of matchtrack
else
return "no track found"
end if
end tell
That is, finds a track based on the persistent ID. I'm trying to get it to work in a MacOS Cocoa Swift application using the Swift Automation as an Apple Event Bridge. I can retrieve the value with:
let trackID = try iTunes.tracks[1].persistentID.get()
I've tried all sorts of statements. This one seems to show the most promise:
let trackRow = try iTunes.tracks[ITUItem.persistentID == "C70EA9CDC276CB6D"].get() as ITUItem
When I run it, I get the error:
Instance member 'persistentID' cannot be used on type 'ITUItem'
The framework is in beta at the best so it may be a bug. Any suggestions on what else to try? I'd ask the author, but I can't find a way to contact him.
Here is part of the sdef file that was generated by the app.
item n : an item
properties
class_ (type, r/o) : the class of the item
container (specifier, r/o) : the container of the item
id (integer, r/o) : the id of the item
index (integer, r/o) : The index of the item in internal application order.
name (text) : the name of the item
persistentID (text, r/o) : the id of the item as a hexadecimal string. This id does not change over time.
properties (record) : every property of the item
Track is a subclass of item.
Fix
When I first tried #matt's suggestion of ITUIts.persistentID, it wouldn't compile. I got the error:
Binary operator '==' cannot be applied to operands of type 'ITUItem' and 'String'
After some back and forth, I realized the problem was that I was missing an import:
import SwiftAutomation
I had it in originally and wasn't sure I needed it so I commented it out. A dozen other calls to it worked fine without it before I got to this one.
Use ITUIts and get rid of as ITUItem. So:
let trackRow = try itunes.tracks[ITUIts.persistentID == "C70EA9CDC276CB6D"].get()
// result will be something along these lines:
// [ITunes().sources.ID(66).libraryPlaylists.ID(93639).fileTracks.ID(95018)]
Herewith, a complete working test along with the results on my machine (of course your numbers will be different):
let itunes = ITunes()
let trackID = try itunes.tracks[1].persistentID.get() as String
print("track ID is", trackID)
// track ID is 689006177BB39343
let trackRows = try itunes.tracks[ITUIts.persistentID == trackID].get() as [ITUItem]
if let trackRow = trackRows.first {
print(trackRow)
// ITunes().sources.ID(66).libraryPlaylists.ID(93639).fileTracks.ID(95018)
}

List directory with custom name applescript

I am looking for a way to display this list with a few custom tags.
Could anybody help me out? I only found this script and is very useful to me if I could alter a few parameters. However I have zero applescript experience.
I would like to have img, description and title as extra variable.
So the output would look like this: ( I will fill in title & description in later ofc. )
{
"title": "",
"gallery": [
{
"img": "101.jpg",
"title": "",
"description": ""
},
{
"img": "102.jpg",
"title": "",
"description": ""
}
]
}
etc for all images in that folder
Please find the script that outputs me my content of a chosen folder as an array. which outputs now as {"P1000443.JPG", "P1000444.JPG"}
tell application "Finder"
set file_list to name of every file of entire contents of (choose folder with prompt "Please select directory.")
end tell
Thanks!
What you're asking is complicated so let me get you started. Run this script, choose a file, and look at the results.
set aFile to choose file
tell application "Finder" to return properties of aFile
You will see all of the properties you can get from a file. Right now in your code you are asking only for the "name" property so you'll have to figure out what properties you want and ask for them in a similar manner as you have asked for the name. Then you'll have to convert all of that information into a nice organized list as you request... that's the difficult part. If you want something that you can't find in the properties then you'll have to figure out how to get that information in another way, for example "description".
EDIT: Based on your comment, I suggest you just use a repeat loop and create a string any way you want. Here's one example. You can use this technique to create the output in any format you want.
set file_list to {"P1000443.JPG", "P1000444.JPG"}
set outputString to ""
repeat with i from 1 to count of file_list
set outputString to outputString & "img: " & item i of file_list & return & "title: " & return & "description: " & return & return
end repeat
return outputString
The output based on the way I formatted it will look like this...
img: P1000443.JPG
title:
description:
img: P1000444.JPG
title:
description:
Good luck.

Why does this throw up an error?

tell application "VoodooPad"
tell document 1
repeat with thisPage from 1 to number of items in pages
set theName to display name of page thisPage
set creationDate to created of page thisPage
set theText to text of page thisPage
tell application "Evernote"
create note with text theText title theName notebook "VoodooPad Imported Notes" tags "imported_from_VoodooPad" created creationDate
end tell
end repeat
end tell
end tell
This produces the following error:
error "VoodooPad got an error: every item of every page of document 1 doesn’t understand the count message." number -1708 from every item of every page of document 1
Any Idea on how to get the script to run?
Try this:
set allPages to pages as list // now you have items in a list
repeat with thisPage from 1 to number of items in allPages
...

Automator variable base on file name (Applescript?)

I am trying to use automator to rename files based on the folder I select as the input. I want to take the folder name and if 1 of 4 phrases are found in the folder name, 1 of 4 variables would be used. I don't know applescript but I feel this is the way to go base on other languages I know.
Can anyone convert the following concept?
if file name contains "USA" then
var = "US"
elseif file name contains "CAN_FR" then
var = "CAFR"
elseif file name contains "CAN_EN" then
var = "CAEN"
end
Much appreciation to anyone that can help.
Try:
on run {input, parameters}
tell application "Finder" to set folderName to name of first item of input
if folderName contains "USA" then
set var to "US"
else if folderName contains "CAN_FR" then
set var to "CAFR"
else if folderName contains "CAN_EN" then
set var to "CAEN"
else
set var to "Not Found"
end if
-- insert your code here
return var
end run

Applescript - Variable Commands Not Working When Using "Choose From List"

I'm trying to create a simple international store for iTunes.
set country to (choose from list {"US", "CA", "UK"} with prompt "What country?")
if country = "US" then
tell application "iTunes"
activate
open location "itmss://itunes.apple.com/WebObjects/MZStore.woa/wa/switchToStoreFront?storeFrontId=143441"
end tell
end if
When I click US, it doesn't do anything with iTunes. What am I doing wrong?
The problem is that the choose from list command is returning a list of the items selected from the list. You can do the following:
set country to (choose from list {"US", "CA", "UK"} with prompt "What country?")
if country = {"US"} then
tell application "iTunes"
activate
open location "itmss://itunes.apple.com/WebObjects/MZStore.woa/wa/switchToStoreFront?storeFrontId=143441"
end tell
end if
Alternatively, you could say if item 1 of country = "US".
Try
if country as text = "US" then

Resources