Hi folks,
Me again, trying to figure out this head scratcher and hoping someone here has an idea on what to do here, I have an applet I’ve been trying to build, I have a functioning app on some systems but I am unable to transfer this between devices, I can transfer the code and re-compile it on each device that I use this on but that’s an extra step I’m trying not to have.
I would ideally love to have where I essentially have an applet that I can transfer between systems or send to another person if they need it to help, when I do that I get and error that the system doesn’t have permission to open the file, I have changed the permissions on all the files to allow everybody read and write permissions, I’m wondering if there is something I need to add to the app itself to get this to allow access, currently all the workbooks are stored in the app itself under Contents:Resources folder within the app itself.
This is one of the errors I’ve been seeing:
Here is the code as it stands:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
set appFile to (path to me as string) & "Contents:Resources:filecheck.txt" -- Path to Version check resources
set rosterPath to (path to me as string) & "Contents:Resources:Rosters:" -- Path to Roster folder
set activeSheet to (path to me as string) & "Contents:Resources:Active Sheet:" -- Path to Active Sheet Files folder
set desktopFolder to (path to desktop folder as string) -- Path to Desktop Folder
set rosterFiles to {"Roster1.numbers", "Roster 2.numbers", "Roster 3.numbers", "Roster 4.numbers"}
set docName to {} -- Placeholder for Roster files
set formSheet to "Roster" -- Roster Sheet
set peopleTable to "People Input" -- People Table
set formMonth to "Monthly Sheet" -- Monthly Sheet
set sheetLog to "Time Log" -- Time Log
set linesBusiness to {"Option 1", "Option 2", "Option 3", "Option 4"} -- LOB List
set theDate to short date string of (current date) -- Read current date (Condensed)
set shortDate to date string of (current date) -- Short date (Just Date)
set currentDate to current date -- Complete date and time
set listLOB to {}
tell application "Finder"
set fileCreationDate to modification date of file appFile
set daysDifference to {currentDate - fileCreationDate} / days
if daysDifference < 180 then
tell application "System Events"
set folderContents to name of every file in folder activeSheet
end tell
repeat with fileName in rosterFiles
if fileName is in folderContents then
set docName to activeSheet & fileName
set listLOB to fileName
exit repeat
end if
end repeat
if listLOB is {} then
set listResult to item 1 of (choose from list linesBusiness with prompt "Choose a Line of Busines:" default items {item 1 of linesBusiness}) -- LOB Selection
set listLOB to item 1 of listResult -- Get the selected file from the list
if listResult = "Option 1" then
set fileToCopy to rosterPath & "Roster 1.numbers" as text
duplicate file fileToCopy to folder activeSheet
delay 7
set fileToOpen to activeSheet & "Roster 1.numbers" as text
set docName to fileToOpen
else
if listResult = "Option 2" then
set fileToCopy to rosterPath & "Roster 2.numbers" as text
duplicate file fileToCopy to folder activeSheet
delay 7
set fileToOpen to activeSheet & "Roster 2.numbers" as text
set docName to fileToOpen
else if listResult = "Option 3" then
set fileToCopy to rosterPath & "Roster 3.numbers" as text
duplicate file fileToCopy to folder activeSheet
delay 7
set fileToOpen to activeSheet & "Roster 3.numbers" as text
set docName to fileToOpen
else if listResult = "Option 4" then
set fileToCopy to rosterPath & "Roster 4.numbers" as text
duplicate file fileToCopy to folder activeSheet
delay 7
set fileToOpen to activeSheet & "Roster 4.numbers" as text
set docName to fileToOpen
end if
end if
end if
display dialog "What Role are you filling today?" buttons {"Roster", "Time Log", "Cancel"} default button "Roster" giving up after 45 -- Initial Input to either open roster or time log
if button returned of result = "Roster" then
tell application "Numbers"
launch
activate
set myDoc to open (docName) as alias
tell document 1
set active sheet to sheet formSheet
tell table peopleTable of sheet formSheet
set endDate to value of cell "A10"
end tell
if currentDate ≥ endDate then
display dialog "Did your assignment end on " & endDate & "?:" buttons {"Yes", "No"} default button "Yes"
if button returned of result = "Yes" then
tell application "Finder"
duplicate file docName to desktopFolder with replacing
quit
delay 3
delete file docName
end tell
else if button returned of result = "No" then
set loanEnd to text returned of (display dialog "When does your assignment end? (MM/DD/YYYY)" default answer "")
tell table peopleTable of sheet formSheet
set value of cell "A10" to loanEnd
end tell
end if
end if
end tell
end tell
else if button returned of result = "Cancel" then
quit
else if button returned of result = "Time Log" then
set columnCount to 5
set rowCount to 5
set headerRow to 1
set headerColumn to 0
set timeStarted to text returned of (display dialog "Enter the time started: (24hr)" default answer "") -- Start Time
set timeFinished to text returned of (display dialog "Enter the time finished: (24hr)" default answer "") -- Finish Time
set taskList to {"Option 1", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6", "Option 7", "Option 8", "Option 9", " "} -- Task list
set theTask to item 1 of (choose from list taskList with prompt "Choose a task:" default items {item 1 of taskList}) -- Task selection
set columnList to {"A", "B", "C", "D", "E"} -- Column Header values
set headerList to {"Date:", "Time Started:", "Time Finished:", "Time Taken:", "Task Completed:"} -- Table column values
set theDuration to my getDuration(timeStarted, timeFinished) -- Calculate time take on task
set valueList to {theDate, timeStarted, timeFinished, theDuration, theTask} -- Table variables for input
tell application "Numbers"
launch
activate
set myDoc to open (docName) as alias
tell sheet sheetLog of document 1
if not (exists table 1) then
set theTable to make new table with properties {header row count:headerRow, column count:columnCount, row count:rowCount, header column count:headerColumn, header columns frozen:"False", name:shortDate}
repeat with i from 1 to 5
set value of cell i of row 1 of theTable to item i of headerList
set alignment of cell i of row 1 of theTable to center
end repeat
end if
end tell
end tell
tell application "Numbers"
activate
tell table 1 of sheet sheetLog of document 1
repeat with rowNumber from 1 to 100
try
set cellValue to value of cell ("A" & rowNumber)
if cellValue is (missing value) then exit repeat
on error
add row below last row
exit repeat
end try
end repeat
repeat with i from 1 to 5
set value of cell ((item i of columnList) & rowNumber) to (item i of valueList)
end repeat
end tell
end tell
end if
else
display dialog "The file is out of Date, please download a new copy" buttons {"Cancel", "Open Link"} default button "Open Link" giving up after 45
set the button_pressed to the button returned of the result
if the button_pressed is "Open Link" then
open location "www.google.com"
quit
return {}
end if
end if
end tell
on getDuration(startTime, finishTime)
set {TID, text item delimiters} to {text item delimiters, ":"}
set startMinutes to ((text item 1 of startTime as integer) * 60) + (text item 2 of startTime as integer)
set finishMinutes to ((text item 1 of finishTime as integer) * 60) + (text item 2 of finishTime as integer)
set durationHours to (finishMinutes - startMinutes) div 60
set durationMinutes to (finishMinutes - startMinutes) mod 60
set text item delimiters to TID
return (durationHours as text) & " hours " & durationMinutes & " minutes"
end getDuration
You all have been an amazing assistance with the trial and error of learning this and appreciate all the help you all have provided already.
Regards,
Mark