Re: Applescript complaining about accessing and writing to a file
Re: Applescript complaining about accessing and writing to a file
- Subject: Re: Applescript complaining about accessing and writing to a file
- From: John Day <email@hidden>
- Date: Fri, 25 Oct 2013 08:32:56 -0400
Here is another approach:
set maxBatch to 1000
set thePathA to "/tmp/jaikoz_itunes_model_noFormat.txt"
set thePathB to "/tmp/jaikoz_itunes_model.txt"
tell application "iTunes"
set mainLibrary to library playlist 1
script s
property theTracks : get every track of mainLibrary
end script
set trackBatch to {}
set batchCount to 0
repeat with nexttrack in s's theTracks
if (class of nexttrack is file track) then
try
set trackname to name of nexttrack
set loc to location of nexttrack
set locpath to POSIX path of loc
set persistid to persistent ID of nexttrack
set end of trackBatch to trackname & "::" & locpath & "::" & persistid & linefeed
set batchCount to batchCount + 1
if batchCount mod maxBatch = 0 then
set trackBatch to trackBatch as text
do shell script "echo " & quoted form of trackBatch & " >> " & quoted form of thePathA
set trackBatch to {}
end if
end try
end if
end repeat
end tell
if trackBatch ≠ {} then
set trackBatch to trackBatch as text
do shell script "echo " & quoted form of trackBatch & " >> " & quoted form of thePathA
set trackBatch to {}
end if
do shell script "sed '/^$/ d' " & quoted form of thePathA & " > " & quoted form of thePathB & " ; rm " & quoted form of thePathA
On Oct 25, 2013, at 5:57 AM, Paul Taylor wrote:
> I get the error message
>
> 25/10/2013 10:39:39.816 iTunes[3366]: AppleEvents/sandbox: Returning errAEPrivilegeError/-10004 and denying dispatch of event rdwr/writ from process 'AppleScript Editor'/0x0-0x24d24d, pid=12717, because it is not entitled to send an AppleEvent to this process.
>
> The errors message occurs every time we access the file
> /tmp/jaikoz_itunes_model.txt, so for the following lines
>
>
> set fileref to open for access (thePath) with write permission (one message)
> set eof fileref to 0
> (one message)
> write nextline & "\n" as "utf8" to fileref starting at eof
> (once per song in itunes)
>
> close access fileref (one message)
>
>
> so the problem is not that we cant talk to itunes but that iTunes
> isn't allow to do things with the filesystem
> It still writes to the file regardless but I think these error messages are slowing it down
>
>
> Am I writing to the file in the wrong place or something ?
>
> tell application "iTunes"
> set thePath to (POSIX file "/tmp/jaikoz_itunes_model.txt")
> set fileref to open for access (thePath) with write permission
> set eof fileref to 0
> set mainLibrary to library playlist 1
> repeat with nexttrack in (get every track of mainLibrary)
> if (class of nexttrack is file track) then
> try
> set trackname to name of nexttrack
> set loc to location of nexttrack
> set locpath to POSIX path of loc
> set persistid to persistent ID of nexttrack
> set nextline to trackname & "::" & locpath & "::" & persistid
> write nextline & "\n" as "utf8" to fileref starting at eof
> end try
> end if
> end repeat
> close access fileref
> end tell
> return ""
>
>
>
>
> Paul
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden