Trying to Add Episode ID to TV Shows via Applescript in iTunes - applescript

I have the following code:
tell application "iTunes"
repeat with thetrack in tracks of playlist "foo"
set showName to name of thetrack
set showName to ((characters 17 through -1 of showName) as string)
set episode ID of thetrack to name of thetrack
end repeat
end tell
I am trying to set the episode ID of TV Shows to the track name. If I comment out the set episode ID line, showName is definititely set to the correct string. When I try to actually set the episode ID however I get the following error:
iTunes got an error: Can’t set episode ID of item 1 of every track of playlist "Fitness & Nutrition" to name of item 1 of every track of playlist "Fitness & Nutrition".
I admit, I'm stumped.

Try:
set episode ID of thetrack to (name of thetrack as text)
because
return class of name of thetrack --> property
and
return class of (name of thetrack as text) --> text

Related

Applescript and empty mail signature / input in value list

I have two questions with my applescript. The script is supposed to send a dropped file as attachment by email and asking the object of the mail from a list.
The content of the message MUST be empty.
1) How to set an "empty" email signature because the content of my mail should be empty. I receive an error code "error in mail impossible to solve signature..."
2) I wish that the user can modify the value list {"00111111111111-number1, "0011111111111-number2"...} and add more numbers. What is the best approach to do this ?
Thanks very much in advance for your suggestions.
property theSubject : "subject"
property theNumber : ""
property theContent : ""
property theSignature : "none"
property onRun : ""
on run
tell application "Finder"
set sel to (get selection)
end tell
set onRun to 1
new_mail(sel)
end run
on open droppedFiles
new_mail(droppedFiles)
end open
on new_mail(theFiles)
set chosen to choose from list {"0011111111111-number1", "0011111111111-number2"} with prompt "Thanks to select"
if chosen is false then return "" -- in case of 'Cancel' return empty string
set theNumber to text 1 thru 13 of (item 1 of chosen) -- as chosen returns a list by default it must be flattened
tell application "Mail"
set newMessage to make new outgoing message with properties {visible:true, subject:theNumber}
tell newMessage
make new to recipient with properties {address:faxboxEmail}
if onRun < 1 then
make new attachment with properties {file name:theFiles as alias} at after last paragraph
end if
set the content to theContent
set message signature of newMessage to signature theSignature
end tell
activate
if onRun < 1 then
send
end if
end tell
end new_mail
to add new item in the list, may be this could help you ?
set BaseList to {"0011111111111-number1", "0011111111111-number2"}
set CList to BaseList & {"Add new item"}
set chosen to choose from list CList with prompt "Thanks to select"
if chosen is false then return "" -- in case of 'Cancel' return empty string
if "Add new item" is in chosen then
set OKNew to false
repeat until OKNew
set NewItem to display dialog "Enter new value :" default answer ""
set OKNew to (button returned of NewItem is "OK") and (text returned of NewItem is not "")
set theNumber to text returned of NewItem
set BaseList to baseList & {theNumber} -- to add the new item in the BaseList
end repeat
else
set theNumber to text 1 thru 13 of (item 1 of chosen) -- as chosen returns a list by default it must be flattened
end if
I also experienced some issues with the signature and the attachement together. if you remove the line "make new attachment..." the signature line is working. Also if you move the signature line before the attachement line, and make a break before the attachement, the signature will be OK. bug ?
Then, based on my tests, if you do not want signature at all, just delete the line "set message signature..." by default, no signature will be set.
My last comment is to reduce your script by adding the content directly in property list of the "make new outgoing message..."
tell application "Mail"
set newMessage to make new outgoing message with properties {visible:true, subject:TheNumber, content:TheContent}
tell newMessage
make new to recipient with properties {address:faxboxmail}
if onRun > 1 then
make new attachment with properties {file name:theFile as alias} at after last paragraph
end if
end tell
activate
end tell
I tried it, and it is creates mail with no content and no signature as expected (Mail 8.2)

Choose from list and write to plist as string, not as array

I've got the following which displays two text input prompts and then queries for PPTP VPN configs and asks the user to 'choose from list'. The results are then saved to a plist file however vpn_name is always encoded inside of two blank arrays. I've tried setting the datatype of vpn_name to string but the same applies.
How can I get this to encode simply as:
<dict>
<key>password</key>
<string>fnkdslfsd</string>
<key>username</key>
<string>fnsdkfnds</string>
<key>vpn_name</key>
<string>SAMSUNG_Android</string>
</dict>
as opposed to how it's currently encoding:
<dict>
<key>password</key>
<string>fnkdslfsd</string>
<key>username</key>
<string>fnsdkfnds</string>
<key>vpn_name</key>
<array>
<array>
<string>SAMSUNG_Android</string>
</array>
</array>
</dict>
Applescript:
property key_path : "~/Library/Preferences/vpn-keys.plist"
property user_name : ""
property pass_word : ""
property vpn_name : ""
tell application "Finder"
if user_name is "" then
set dialog_1 to display dialog "Please enter your server username: " default answer ""
set the user_name to the text returned of dialog_1
end if
if pass_word is "" then
set dialog_2 to display dialog "Please enter your server password: " default answer ""
set the pass_word to the text returned of dialog_2
end if
if vpn_name is "" then
tell application "System Events"
tell current location of network preferences
set VPN_list to get name of every service whose (kind is greater than 11 and kind is less than 17)
end tell
end tell
vpn_name as string
set vpn_name to {choose from list VPN_list with prompt "Select Office VPN"}
end if
tell application "System Events"
set the parent_dictionary to make new property list item with properties {kind:record}
set the plistfile_path to key_path
set this_plistfile to ¬
make new property list file with properties {contents:parent_dictionary, name:plistfile_path}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"username", value:user_name}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"password", value:pass_word}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"vpn_name", value:vpn_name}
end tell
end tell
choose from list returns a list of items selected and returns false when canceled. You defined an empty string before choose from list command is invoked but in AppleScript that doesn't have any effect between lines. So what you can do is test if the results are false before continuing because unlike a display dialog the script continues when the user pressed the cancel button. Then set value of new property list item to item 1 of vpn_name.
property key_path : "~/Library/Preferences/vpn-keys.plist"
property user_name : ""
property pass_word : ""
property vpn_name : ""
tell application "Finder"
if user_name is "" then
set dialog_1 to display dialog "Please enter your server username: " default answer ""
set the user_name to the text returned of dialog_1
end if
if pass_word is "" then
set dialog_2 to display dialog "Please enter your server password: " default answer ""
set the pass_word to the text returned of dialog_2
end if
if vpn_name is "" then
set vpn_name to false
tell application "System Events"
tell current location of network preferences
set VPN_list to get name of every service whose (kind is greater than 11 and kind is less than 17)
end tell
end tell
set vpn_name to choose from list VPN_list with prompt "Select Office VPN"
if vpn_name is false then return --stop, user pressed cancel
end if
tell application "System Events"
set the parent_dictionary to make new property list item with properties {kind:record}
set the plistfile_path to key_path
set this_plistfile to ¬
make new property list file with properties {contents:parent_dictionary, name:plistfile_path}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"username", value:user_name}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"password", value:pass_word}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"vpn_name", value:item 1 of vpn_name}
end tell
end tell

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
...

How do I select playlists in a subfolder in Itunes using AppleScript?

This code will return all the play lists in iTunes:
tell application "iTunes"
get name of playlists
end tell
How do I return all play lists in a subfolder?
Thank you in advance.
You can try something like this:
tell application "iTunes"
set myList to {}
set myFolder to folder playlist "testFolder"
set myPlaylists to playlists
repeat with aPlaylist in myPlaylists
try
if aPlaylist's parent = myFolder then set end of myList to aPlaylist's name
end try
end repeat
return myList
end tell

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