I have baby photos in a folder and I want to upload them one at a time about every hour (4000 secs not 3600 secs) to a shared iCloud album that all my relatives see on their iPhones and iPads and macs. Here is my applescript saved as an application with the keep open box checked. I think it's not quite right. What's wrong?
on idle
set importFolder to "Amac:Users:AbuDavid:Downloads:uploadBABY"
set extensionsList to {"jpg", "png", "tiff"}
tell application "Finder" to set theFiles to some file of importFolder whose name extension is in extensionsList
if (count of theFiles) < 1 then
display dialog "No images selected!" buttons "OK"
else
set albumName to "BabyDouDou"
set timeNow to time string of (current date)
set today to date string of (current date)
set albumName to albumName & " " & timeNow & " " & today
set imageList to theFiles
tell application "Photos"
activate
delay 2
import imageList into albumName skip check duplicates yes
end tell
tell application "Finder" to move theFiles to trash
end if
return 4000
end idle
There are some issues:
The Finder needs the keyword folder – not just a literal string – to specify a folder.
some file returns always one file so the count command fails and returns always 0.
albumName is a literal string as well rather than a object specifier.
Photos.app expects alias specifiers for the files to be imported rather than Finder object specifiers.
Try this
on idle
set importFolder to (path to downloads folder as text) & "uploadBABY"
set extensionsList to {"jpg", "png", "tiff"}
tell application "Finder" to set theFiles to files of folder importFolder whose name extension is in extensionsList
if (count theFiles) < 1 then
display dialog "No images selected!" buttons "OK"
else
set theFile to some item of theFiles
set albumName to "BabyDouDou"
set timeNow to time string of (current date)
set today to date string of (current date)
set albumName to albumName & " " & timeNow & " " & today
set imageList to {theFile as alias}
tell application "Photos"
activate
delay 2
if not (exists container albumName) then
set theAlbum to make new album
set name of theAlbum to albumName
else
set theAlbum to container albumName
end if
import imageList into theAlbum skip check duplicates yes
end tell
tell application "Finder" to move theFiles to trash
end if
return 4000
end idle
Made a small change to only delete the image that was uploaded and not all the images. Thank you so much.
on idle
set importFolder to (path to downloads folder as text) & "uploadBABY"
set extensionsList to {"jpg", "png", "tiff"}
tell application "Finder" to set theFiles to files of folder importFolder whose name extension is in extensionsList
if (count theFiles) < 1 then
display dialog "No images selected!" buttons "OK"
else
set theFile to some item of theFiles
set albumName to "testscript"
set imageList to {theFile as alias}
tell application "Photos"
activate
delay 2
if not (exists container albumName) then
set theAlbum to make new album
set name of theAlbum to albumName
else
set theAlbum to container albumName
end if
import imageList into theAlbum skip check duplicates yes
end tell
tell application "Finder" to move theFile to trash
end if
return 7
end idle
Related
I am writing an AppleScript to handle some MTS files. The script recursively iterates through the subfolders of the top-level folder "Volumes:G-Drive:video". The subfolders are arranged into year folders, starting with the folder named "2005" for the year 2005. The runtime error is occurring with the very first folder "2005" that the script tries to iterate. I suspected it is something to do with how I am handling aliases and text, but I am stumped at this point how to fix it. The error at runtime is this:
Can’t make {alias "G-DRIVE:video:", "2005:"} into type integer.
I don't know where in my code an integer type comes into play so as to get this error. Script Editor doesn't point me to the location of the runtime error in the code, so i don't know how to figure out which line is causing this either.
set folderName to "Volumes:G-Drive:video" as alias
my processFolder("", folderName)
on processFolder(root, folderNameToProcess)
tell application "Finder"
set theItems to every file of folder (root & folderNameToProcess)
repeat with theFile in theItems
set Nm to name of theFile as text
set Ex to name extension of theFile
if Nm does not contain "-c" and Ex is "MTS" then
set NmMinusExt to my remove_extension(Nm)
set logMsg to "Deleting " & Nm
my logThis(logMsg)
tell application "Finder" to delete theFile
end if
end repeat
set theItems to every file of folder (root & folderNameToProcess)
repeat with theFile in theItems
set Nm to name of theFile as text
set Ex to name extension of theFile
--tell (info for theFile) to set {Nm, Ex} to {name, name extension}
if Nm contains "-c" and Ex is "MTS" then
set NmMinusExt to my remove_extension(Nm)
set shortNm to my remove_lastTwoCharacters(NmMinusExt)
set name of theFile to shortNm & ".MTS" as text
set logMsg to "Renaming " & Nm
my logThis(logMsg)
--set lastTwoLetters to characters (((length of Nm) - 2) as number) thru (((length of Nm) - 0) as number) of (Nm as text)
--if lastTwoLetters is "-c" then
--display notification lastTwoLetters
--end if
end if
end repeat
set theFolders to name of folders of folder (root & folderNameToProcess)
repeat with theFolder in theFolders
copy theFolder as string to TheFolderName
display notification "found folder named: " & TheFolderName
set firstChar to (text 1 thru 1 of TheFolderName)
if firstChar is not "." then
--display dialog (folderNameToProcess & TheFolderName & ":")
try
my processFolder(folderNameToProcess, TheFolderName & ":")
on error errStr number errorNumber
display dialog errStr
end try
end if
end repeat
end tell
return
end processFolder
on remove_extension(this_name)
if this_name contains "." then
set this_name to ¬
(the reverse of every character of this_name) as string
set x to the offset of "." in this_name
set this_name to (text (x + 1) thru -1 of this_name)
set this_name to (the reverse of every character of this_name) as string
end if
return this_name
end remove_extension
on remove_lastTwoCharacters(this_name)
set this_name to ¬
(the reverse of every character of this_name) as string
set this_name to (text 3 thru -1 of this_name)
set this_name to (the reverse of every character of this_name) as string
return this_name
end remove_lastTwoCharacters
The Events pane of Script Editor produces the following trace:
tell application "Finder"
get every file of folder "G-DRIVE:video:"
get every file of folder "G-DRIVE:video:"
get name of every folder of folder "G-DRIVE:video:"
display notification "found folder named: 2005"
end tell
tell application "Script Editor"
display notification "found folder named: 2005"
end tell
tell application "Finder"
get every file of folder {alias "G-DRIVE:video:", "2005:"}
display dialog "Finder got an error: Can’t make {alias \"G-DRIVE:video:\", \"2005:\"} into type integer."
folderName is an alias. The attempt to concatenate an alias and a string creates a list which the error indicates.
The solution is to use only (HFS) string paths.
Replace
set folderName to "Volumes:G-Drive:video" as alias
with
set folderName to "G-Drive:video:"
The trailing colon is crucial to be able to add path components
Sorry if it has already discussed but I'm unable to find an answer.
I would like to add files from a choosen folder to an existing iTunes' playlist.
I don't want to copy/duplicate these files (so iTunes would create a new folder inside its Music folder).
If I use:
add myFolder to playlist playListName
songs are duplicated in a new "Music" folder
If I use:
add myFile to playlist playListName
I have a type error, something about «class cUsP» id 20647 of «class cSrc» id 66 of application "iTunes".
My app code contains several subroutines, not easy to understand unless I post the entire code.
myFolder can be defined by dropping a folder onto the app, or by command choose folder.
Then, playListName is extracted from the choosen folder's pathname.
Then, folder is processed like this, in order to create playlist:
on processFolder(thisFolder, playListName)
tell application "iTunes"
activate
-------------------------------- create playlist
try
set newPlaylist to (make new user playlist with properties {name:playListName})
set view of browser window 1 to newPlaylist
on error errMsg
beep
my dlog("Unable to create playlist " & my kwote(playListName) & "." & return & return & errMsg, {"Abort"}, appTitle, "error")
return false
end try
--***add thisFolder to newPlaylist -- create new "Music folder" and duplicate files !!!
--------------- add files --> tracks
tell application "Finder"
repeat with thisFile in (get every file of folder thisFolder)
if (my isValidFile(thisFile)) then
tell application "iTunes"
try
add thisFile to playlist playListName -- ERROR !!!
on error errMsg
beep
my dlog("Unable to add file " & my kwote(thisFile as text) & "." & return & return & errMsg, {"Abort"}, appTitle, "error")
return false
end try
end tell
end if
end repeat
end tell
return true
end tell
end processFolder
on isValidFile(thisFile)
tell application "Finder"
set the fileInfo to (info for thisFile as alias)
if (mp3Check) then
if (alias of the fileInfo is false) and ((the file type of the fileInfo is in the typesList) or (the name extension of the fileInfo is in the extensionsList)) then return true
else
if (alias of the fileInfo is false) then return true
end if
return false
end tell
end isValidFile
Thank you.
I am trying to achieve some automation in my current workflow. I'd like to drop images to my applescript application, then have it autoresize to the size as set by the user.
I prompt the user a dialog, where one can enter the pixelsize for width, then have the script do the donkey work.
For some reason it is not running properly, and for the life of my i can't figure out why.
Any and all help is very much appreciated!
Here's the script:
display dialog "What is the desired size?" default answer "64"
set my_answer to text returned of result
on open some_items
repeat with this_item in some_items
try
rescale_and_save(this_item)
end try
end repeat
end open
to rescale_and_save(this_item)
tell application "Image Events"
launch
set the target_width to my_answer
-- open the image file
set this_image to open this_item
set typ to this_image's file type
copy dimensions of this_image to {current_width, current_height}
if current_width is greater than current_height then
scale this_image to size target_width
else
-- figure out new height
-- y2 = (y1 * x2) / x1
set the new_height to (current_height * target_width) / current_width
scale this_image to size new_height
end if
tell application "Finder" to set new_item to ¬
(container of this_item as string) & "scaled." & (name of this_item)
save this_image in new_item as typ
end tell
end rescale_and_save
I wrote this script a while ago. It will re-sample an image so its largest dimension is the input value.
on open of myFiles
set my_answer to text returned of (display dialog "What is the desired size?" default answer "64")
repeat with aFile in myFiles
set filePath to aFile's POSIX path
set bPath to (do shell script "dirname " & quoted form of filePath)
tell application "System Events" to set {fileName, fileExt} to {name, name extension} of aFile
set baseName to text 1 thru ((get offset of "." & fileExt in fileName) - 1) of fileName
do shell script "sips " & quoted form of aFile's POSIX path & " -Z " & my_answer & " --out " & quoted form of (bPath & "/" & baseName & "-" & my_answer & "." & fileExt as text)
end repeat
end open
all folder & subfolder of outlook (list below) pass in applescript variable(selectedMessages).
any way to pass one by one or all folder in applescript (using applescript).
folder structure of outlook mail folder :
SIGMACO
Inbox
-McAfee Anti-Spam
Drafts
Sent Items
Deleted Items
Junk E-mail
RSS Feeds
Sync Issues
-Conflicts
-Local Failures
ON MY COMPUTER
Inbox
Drafts
Sent Items
Deleted Items
Junk E-mail
archive PST
-Deleted Items
-Sent Items
SMART FOLDERS
Flagged Mail
+++++++++++
tell application "Microsoft Outlook"
with timeout of 8.8E+8 seconds
set selectedMessages to every messagge of folder "deleted Items" of on my coputer
end timeout
end tell
find some code for list foldeer and subfoldeeer.
global AllFolders
set AllFolders to {}
global ContainerName
set ContainerName to ""
tell application "Microsoft Outlook"
set allMailFolders to get mail folders
repeat with currentFolder in allMailFolders
set FolderName to name of currentFolder
set PathSoFar to ""
if FolderName is not missing value and (container of currentFolder is not missing value or account of currentFolder is not missing value) then
set ContainerName to ":"
set theContainer to currentFolder
repeat while ContainerName is not ""
set ContainerName to ""
try
set theContainer to container of theContainer
set ContainerName to name of theContainer
if ContainerName is missing value then
set theAccount to account of theContainer
if theAccount is not missing value then
set AccountName to name of theAccount
set PathSoFar to (AccountName) & ":" & PathSoFar
end if
else
set PathSoFar to (ContainerName) & ":" & PathSoFar
end if
end try
end repeat
set end of AllFolders to {PathSoFar & ":" & (FolderName)}
end if
end repeat
return AllFolders
end tell
Anyone of you guys could point me to why this applescript (which was working on snow leopard) does not work anymore on 10.7 Lion.
It intend to copy the file named "folder.jpg" from each album folder into ID3 tags of selected mp3 in iTunes.
property tempfile : ((path to temporary items as string) & "itunespicturefile_temporaire.pict")
global vPictFolder
tell application "iTunes"
set v_TrackSelection to selection
if v_TrackSelection is not {} then
repeat with vTrack in v_TrackSelection
set vPictFolder to my (ParentFromPath(location of vTrack as string)) as text
set thisPict to my getpictData("folder.jpg")
if thisPict is not "" then
delete artworks of vTrack
set data of artwork 1 of vTrack to (thisPict)
end if
end repeat
else
display dialog ("select tracks first !")
end if
end tell
on getpictData(vAlbumpictName)
tell application "Finder" to tell file vAlbumpictName of folder vPictFolder to if exists then
set t_file to it as string
else
display dialog vPictFolder & vAlbumpictName
return ""
end if
do shell script "/opt/local/bin/convert " & quoted form of POSIX path of t_file & " " & quoted form of POSIX path of tempfile
display dialog "ok"
return read (tempfile as alias) from 513 as picture
end getpictData
on ParentFromPath(thePath)
set wantPath to true
set thePath to (thePath as text)
set saveDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set pathAsList to text items of thePath
if the last character of thePath is ":" then
set idx to (the number of text items in thePath) - 2
else
set idx to -2
end if
if wantPath then
set folderName to ((text items 1 through idx of pathAsList) as text) & ":"
else
set folderName to item idx of pathAsList
end if
set AppleScript's text item delimiters to saveDelim
return folderName
end ParentFromPath
Because Picture format (".pict") is not supported on Lion and newer OS.
You can use the term picture to read a image file (JPEG, PNG, ...), the format will not be in the Picture format , but the original format of the file.
tell application "iTunes"
set v_TrackSelection to selection
if v_TrackSelection is not {} then
repeat with vTrack in v_TrackSelection
set vPictFolder to my (ParentFromPath(location of vTrack as string)) as text
set thisPict to my getpictData(vPictFolder & "folder.jpg")
if thisPict is not "" then
delete artworks of vTrack
set data of artwork 1 of vTrack to (thisPict)
end if
end repeat
else
display dialog ("select tracks first !")
end if
end tell
on getpictData(tFile)
try
return (read (tFile as alias) as picture)
end try
display dialog tFile
return "" -- not exists
end getpictData